2014-06-12 40 views
0

試圖簡單地有一個場景,我有遊戲玩法和hud。因爲我已經定位了場景(包含兩個圖層),所以我認爲這就是爲什麼我的菜單按鈕移動,即使它在Hud層。 要解決它,我認爲我會也許不得不CCNode 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; 
} 

但當時我只是得到:

上我將如何建立一個場景只是困惑,最初有2層 - 將位置保持在右上方作爲平視顯示器,另一個在告訴時將其與場景進行滾動顯示。

回答

0

這與你在這裏提出的其他問題有關(Adding a Hud Layer to Scene Cocos2d-3),我發佈了答案。將來最好在第一個問題中修改原始的OP,而不是創建一個幾乎相同的新問題。

希望這有助於。