0

IOS6用のcocos2Dゲームエンジンを使ってゲームを開発しています。初めてゲームを開始するには、次のコードを使用します。

-(void)addGameScene

{

CCDirector *director = [CCDirector sharedDirector];
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
    [CCDirector setDirectorType:kCCDirectorTypeMainLoop];
else {
    [CCDirector setDirectorType:kCCDirectorTypeDisplayLink];
}

// Init the View Controller
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
if(!glView)
    glView = [[EAGLView alloc] initWithFrame:[window bounds]];
[director setOpenGLView:glView];

[director setOpenGLView:glView];
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
[viewController setView:glView];
[window setRootViewController:viewController];
[window addSubview: viewController.view];
[window makeKeyAndVisible];
[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];
}

ゲーム シーンから出るとき、cocos2D ゲーム エンジンを終了せず、代わりにアニメーションを停止して glView を非表示にします。私はこのコードを使用します。

  [[CCDirector sharedDirector] stopAnimation];
CATransition *animation3 = [CATransition animation];
[animation3 setDuration:0.5f];
[animation3 setType:kCATransitionFade];
[animation3 setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[[CCDirector sharedDirector].openGLView layer] addAnimation:animation3 forKey:@"SwitchToView"];
[[CCDirector sharedDirector].openGLView setHidden:YES];

プレイするゲームを再度開始するときは、次のコードを使用します。

[[CCDirector sharedDirector].openGLView setHidden:NO];
[[CCDirector sharedDirector] replaceScene:[HelloWorldLayer scene]];
[[CCDirector sharedDirector] startAnimation];

それは正常に動作します。

しかし、初めてゲームを起動して、ゲーム シーンから戻って、デバイスのホーム ボタンを押してアプリケーションを終了し、再びアプリケーションを起動してから、ゲームを再起動すると、このシナリオではクラッシュします。

コンソールに次のように出力されます。

2012-12-12 15:53:24.847 CasinoApp[2856:12203] -[HelloWorldLayer init] : Screen width 480.00 screen height 320.00
2012-12-12 15:53:24.848 CasinoApp[2856:12203] 10.000000

2012-12-12 15:53:24.849 CasinoApp[2856:12203] -[CCTexture2D(Image) initWithImage:resolutionType:] : cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2012-12-12 15:53:24.850 CasinoApp[2856:12203] -[CCTextureCache addImage:] : cocos2d: Couldn't add image:lines in CCTextureCache

2012-12-12 15:53:24.850 CasinoApp[2856:12203] *** Assertion failure in -[CCDirectorTimer startAnimation], /Users/rakesh/Desktop/Ryan/Code/CasinoApp/CasinoApp/libs/cocos2d/Platforms/iOS/CCDirectorIOS.m:498

この理由を誰か教えてください。感謝します..ありがとう。

4

2 に答える 2

1

CCScene クラスのシーン メソッドを使用できる場合、クラスが再初期化され、シーン全体が再構築されます。したがって、シーンを同じシーンに置き換える場合は、アニメーションを再度開始する必要はありません。また、glView を非表示にしている場合は、glView を再表示する前に、ディレクターを一時停止して再開することができます。

[[CCDirector shareDirector]pause];
[[CCDirector sharedDirector].openGLView setHidden:YES];

[[CCDirector shareDirector]resume];
[[CCDirector sharedDirector].openGLView setHidden:YES];
[[CCDirector sharedDirector] replaceScene:[HelloWorldLayer scene]];
于 2014-11-11T12:51:40.793 に答える
0

試す

[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];

[[CCDirector sharedDirector] stopAnimation]; // call this to make sure you don't start a second display link
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] startAnimation];

お役に立てれば!

于 2012-12-13T09:36:18.363 に答える