2012-08-18 150 views
1

我想從使圖像中的玩家從當前場景(遊戲場景)回到菜單場景,重置當前場景(遊戲場景)的按鈕。Cocos2D菜單按鈕

回答

0

使用如下代碼:

-(void)showBackBtnMenu 
{ 
    CCSprite *backButtonNormal = [CCSprite   spriteWithSpriteFrameName:@"btnBackNormal.png"]; //Make sure u already added this sprite sheet. Otherwise use sprite from file. 
    CCSprite *backButtonSelected = [CCSprite spriteWithSpriteFrameName:@"btnBackSelected.png"]; 

    CCMenuItemSprite *backButton = [CCMenuItemSprite itemFromNormalSprite:backButtonNormal selectedSprite:backButtonSelected disabledSprite:nil target:self selector:@selector(backBtnPress:)]; 

    backButton.position = ccp(63.0f, 34.0f); 

CCMenu *menu = [CCMenu menuWithItems:backButton, nil]; 
    menu.position = ccp(0,0); 
    [self addChild:menu z:3]; //Make sure this z value is higher than ur background 
} 


-(void)backBtnPress:(id)sender 
{ 
     [[CCDirector sharedDirector] replaceScene:[transition transitionWithDuration:duration scene:[MyMainMenu scene]]]; 
} 
+0

代碼工作,但我的按鈕犯規出現任何幫助嗎? – DarkMoonLLC

+1

您可能想要檢查是否添加了該按鈕,或者是否被更高級別的z對象覆蓋。 – stenger96