试图简单地有一个场景,我有游戏,和hud。因为我让它定位场景(其中包含两个层),所以我认为这就是为什么我的菜单按钮在Hud层中移动的原因。为了解决这个问题,我想我可能需要改变这一行。
[self setCenterOfScreen: mainChar.position];像这样的事情:
[gameLayer setCenterOfScreen: mainChar.position];但我明白了:
CCNode没有可见的@接口声明选择器'setCenterOfScreen:‘
这里是GameScene (我认为问题所在):
+ (GameScene *)scene
{
return [[self alloc] init];
}
// -----------------------------------------------------------------------
- (id)init
{
self = [super init];
if (!self) return(nil);
CGSize winSize = [CCDirector sharedDirector].viewSize;
self.userInteractionEnabled = YES;
self.theMap = [CCTiledMap tiledMapWithFile:@"AftermathRpg.tmx"];
self.contentSize = theMap.contentSize;
CCNode *gameLayer = [CCNode node];
gameLayer.userInteractionEnabled = YES;
gameLayer.contentSize = self.contentSize;
[self addChild:gameLayer];
[gameLayer addChild:theMap z:-1];
self.mainChar = [CCSprite spriteWithImageNamed:@"mainChar.png"];
mainChar.position = ccp(200,300);
[gameLayer addChild:mainChar];
// POSSIBLY WHY BOTH LAYERS ARE SHIFTING, RATHER THEN HUD STANDING STILL,
// I essentially want the gameLayer to be centered on screen, not both.
// I tried [gameLayer setCenterOfScreen: mainChar.position] but got error posted above
[self setCenterOfScreen: mainChar.position];
CCNode *hudLayer = [CCNode node];
hudLayer.userInteractionEnabled = YES;
hudLayer.position = ccp(winSize.width * 0.9, winSize.height * 0.9);
[self addChild:hudLayer];
CCButton *backButton = [CCButton buttonWithTitle:@"[ Menu ]" fontName:@"Verdana-Bold" fontSize:18.0f];
backButton.positionType = CCPositionTypeNormalized;
backButton.position = ccp(0.85f, 0.95f); // Top Right of screen
[backButton setTarget:self selector:@selector(onBackClicked:)];
[hudLayer addChild:backButton];
return self;
}但我得到的只是:
我只是困惑如何设置一个场景,最初有两个层-一个保持位置,例如右上角作为一个HUD,另一个滚动与场景的游戏时,告诉它。
发布于 2014-06-12 18:22:37
这与你在这里问的另一个问题(Adding a Hud Layer to Scene Cocos2d-3)有关,我贴出了答案。在将来,最好在第一个问题中修改原来的操作操作,而不是创建一个几乎相同的新问题。
希望这能帮上忙。
https://stackoverflow.com/questions/24189348
复制相似问题