1

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

4

1 回答 1

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]]];
}
于 2012-08-19T04:59:05.630 回答