Cocos2D菜单按钮

时间:2012-08-18 22:26:58

标签: iphone objective-c sdk cocos2d-iphone

我想从图像中制作一个按钮,将玩家从当前场景(游戏场景)带回菜单场景,重置当前场景(游戏场景)。

1 个答案:

答案 0 :(得分: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]]];
}