尝试简单地拥有一个我拥有游戏玩法的场景和hud。由于我定位了场景(包含两个图层),我认为这就是为什么我的菜单按钮正在移动,即使它在Hud图层中也是如此。 为了解决这个问题,我认为我可能不得不改变这一行
[self setCenterOfScreen: mainChar.position];
这样的事情:
[gameLayer setCenterOfScreen: mainChar.position];
但后来我明白了:
CCNode没有可见的@interface声明选择器 ' 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;
}
然后我得到:
对于我如何设置一个场景感到困惑,最初有2层 - 一个保持位置在右上方称为HUD,另一个在场景中滚动游戏时告诉它。
答案 0 :(得分:0)
这与您在此处提出的其他问题(Adding a Hud Layer to Scene Cocos2d-3)有关,我将答案发布到了。将来最好在第一个问题中修改原始OP,而不是创建一个几乎相同的新问题。
希望这会有所帮助。