试图简单地拥有一个我有游戏玩法和平视显示器的场景。因为我有它定位场景(包含两个图层),所以我认为这就是我的菜单按钮移动的原因,即使它在 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,另一层在告诉它时随着游戏场景滚动。