как вызвать метод и остановить анимацию cocos2d? - PullRequest
1 голос
/ 21 июня 2011

У меня есть 2 кнопки, игра, помощь и один фон

-(void) mainMenu {
//BackgroundImage
//Play Button
//Help Button
}

Когда вы нажмете PlayButton, он вызовет метод, имеющий в своем теле следующий код.

-(void)Play {

     // Try to use CADisplayLink director
 // if it fails (SDK < 3.1) use the default director


 if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
 [CCDirector setDirectorType:kCCDirectorTypeDefault];

 CCDirector *director = [CCDirector sharedDirector];

// Init the View Controller

//
// Create the EAGLView manually
//  1. Create a RGB565 format. Alternative: RGBA8
//  2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
//
//
CGRect rect = CGRectMake(0, 0, 320, 480);

 EAGLView *glView = [EAGLView viewWithFrame:rect
 pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
 depthFormat:0                      // GL_DEPTH_COMPONENT16_OES
 ];

 // attach the openglView to the director
 [director setOpenGLView:glView];

 // // Enables High Res mode (Retina Display) on iPhone 4 and maintains low     res     on all other devices
 // if( ! [director enableRetinaDisplay:YES] )
 //     CCLOG(@"Retina Display Not supported");

 //
 // VERY IMPORTANT:
 // If the rotation is going to be controlled by a UIViewController
 // then the device orientation should be "Portrait".
 //
 // IMPORTANT:
 // By default, this template only supports Landscape orientations.
 // Edit the RootViewController.m file to edit the supported orientations.
 //
/*
 #if GAME_AUTOROTATION == kGameAutorotationUIViewController
 [director setDeviceOrientation:kCCDeviceOrientationPortrait];
 #else
 [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
 #endif
 */

 [director setAnimationInterval:1.0/60];
 [director setDisplayFPS:YES];


 // make the OpenGLView a child of the view controller
 [self.view addSubview:glView];

// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

// Removes the startup flicker
//[self removeStartupFlicker];

// Run the intro Scene
//[[CCDirector sharedDirector] runWithScene: [HelloWorldScene node]];

[[CCDirector sharedDirector] runWithScene: [PongLayer node]];
//[[CCDirector sharedDirector] replaceScene:[[[PongLayer alloc] init] autorelease]];
}

Теперь во время игры я хочу снова вызвать экран главного меню, чтобы игрок снова начал игру, как я могу остановить анимацию и вернуться в главное меню

1 Ответ

0 голосов
/ 20 июня 2013

Ваше главное меню, это UIViewController, а не объект cocos?Если я правильно понимаю, что вы делаете, и так как вы настроили glView директора в Play, вы можете завершить директор с помощью [[CCDirector sharedDirector] end] и удалить glView ([glView removeFromSuperView]) из родительского элемента.1002 * Я предполагаю, что меню все еще там, под glView, так как вы программно добавляете glView как вспомогательное представление «self».Надеюсь, это помогло.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...