我有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]];
}
现在在比赛期间我想回到主菜单屏幕,这样玩家就可以重新开始比赛, 如何停止动画并返回mainMenu
答案 0 :(得分:0)
你的主菜单,它是一个UIViewController而不是一个cocos对象?如果我理解你正在做什么,并且因为你在Play中设置了导演的glView,你可以用[[CCDirector sharedDirector] end]结束导演并从父节点中删除glView([glView removeFromSuperView])。
我假设菜单仍然在glView下面,因为你以编程方式将glView添加为'self'的子视图。希望这有帮助。