2011-06-21 67 views
1

我有2個按鈕,播放,幫助和一個背景如何調用一個方法並停止cocos2d動畫?

-(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]]; 
} 

現在比賽中我要調用的MAINMENU屏幕的背面,讓玩家應該重新開始遊戲, 我怎麼能停止動畫,反悔MAINMENU

回答

0

你的主菜單,是一個UIViewController而不是一個椰子對象?如果我明白你在做什麼,並且由於你在Play中設置了導演的glView,你可以用[[CCDirector sharedDirector] end]結束導演,並從父節點中刪除glView([glView removeFromSuperView])。

我認爲菜單仍然存在於glView下面,因爲您正在以編程方式將glView添加爲「自我」的子視圖。希望這有助於。