0

ゲームプレイがあり、その上に を子としてscene追加します。CCNodeゲーム オーバー ノードにリプレイCCButtonがあります。

ボタンは、ゲーム プレイ シーンを再開することになっています。問題は、「再起動」ボタンを押すと、行は通過しますが、実行されないことですreplaceScene。また、押しても強調表示されません。関連するコードは次のとおりです。

NodeGamePlay クラス (.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];
}

問題は、「ボタンが押されました」と出力され、メソッドの残りのコードも実行されますが、何も起こりません。

私が間違っていることを教えていただければ幸いです。

ありがとう!

4

1 に答える 1

3

CCDirector を一時停止しているため、機能しません。次の行を削除します。

[[CCDirector sharedDirector] pause];

または、本当に必要な場合は、シーンを置き換える前にディレクターを再開してください。

[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] replaceScene:[GamePlayScene scene] withTransition:t];
于 2014-04-27T22:13:56.060 に答える