我有一个游戏玩法scene
,我CCNode
小时候在上面添加了一个。我的 Game Over 节点中有重播CCButton
。
该按钮应该重新启动游戏场景。问题是,当我按下“重新启动”按钮时,它会通过线路但它不会执行replaceScene
。按下时它也不会突出显示。这是我的相关代码:
Node
我在 GamePlay 类 (.m) 中添加 Game Over 的代码:
CCNode GameOver = [[GameOverNode alloc] init];
[self unscheduleAllSelectors];
[self stopAllActions];
[[OALSimpleAudio sharedInstance] stopBg];
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];
[self addChild:GameOver z:5];
这是 GameOver 类 (.h) 的代码:
@interface GameOverNode:CCNode {
CCButton *_aButton;
}
@property (nonatomic, retain) CCButton *aButton;
- (id)init;
- (void)ButtonPressed:(id)sender;
和游戏结束(.m):
-(id)init {
if ( self = [super init] ){
CCSpriteFrame *replayFrame = [CCSpriteFrame frameWithImageNamed:@"Replay.png"];
_aButton = [CCButton buttonWithTitle:@"" spriteFrame:replayFrame];
_aButton.position = ccp(200,200);
[_aButton setTarget:self selector:@selector(ButtonPressed:)];
[self addChild:_aButton z:2];
}
return self;
}
- (void)ButtonPressed:(id)sender
{
NSLog(@"Button pressed");
CCTransition* t = [CCTransition transitionFadeWithDuration:0.4f];
t.outgoingSceneAnimated = YES;
t.incomingSceneAnimated = YES;
[[CCDirector sharedDirector] replaceScene:[GamePlayScene scene] withTransition:t];
}
问题是,它打印出“按下按钮”,还遍历了该方法的其余代码,但没有任何反应。
如果你能让我知道我做错了什么,我将不胜感激。
谢谢!