ゲームプレイがあり、その上に を子としてscene
追加します。CCNode
ゲーム オーバー ノードにリプレイCCButton
があります。
ボタンは、ゲーム プレイ シーンを再開することになっています。問題は、「再起動」ボタンを押すと、行は通過しますが、実行されないことですreplaceScene
。また、押しても強調表示されません。関連するコードは次のとおりです。
Node
GamePlay クラス (.m) にゲーム オーバーを追加するコード:
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];
}
問題は、「ボタンが押されました」と出力され、メソッドの残りのコードも実行されますが、何も起こりません。
私が間違っていることを教えていただければ幸いです。
ありがとう!