我正在学习cocos2d-iphone,现在刚开始不久就遇到了问题。。。我用的是0.99.5的版本,我想写一个游戏刚进去的菜单,只是一个单纯的菜单,没有写其它东西。代码编译能通过,可模拟器在运行时只显示个cocos2d的logo就退出来了,求高手帮忙看看是哪的问题,下面是主要代码:
我写的菜单SysMenu:
SysMenu.h:
[lang=
#import <Foundation/Foundation.h>
#import “cocos2d.h”
@interface SysMenu : CCLayer {
}
- (id) scene;
@end
]
SysMenu.m:
[lang=
#import “SysMenu.h”
@implementation SysMenu
-
(id) scene
{
CCScene *scene = ;SysMenu *layer = ;
;
return scene;
}
-
(id) init
{
self = ;
if (self) {
CCSprite *sp = ;
sp.anchorPoint = CGPointZero;; ; ; CCMenuItem *newGame = [CCMenuItemFont itemFromString:@"New Game" target:self selector:@selector(newGame:)]; CCMenuItem *loadGame = [CCMenuItemFont itemFromString:@"Load Game" target:self selector:@selector(loadGame:)]; CCMenuItem *setting = [CCMenuItemFont itemFromString:@"Setting" target:self selector:@selector(OnSettings:)]; CCMenuItem *help = [CCMenuItemFont itemFromString:@"Help" target:self selector:@selector(help:)]; CCMenuItem *quit = [CCMenuItemFont itemFromString:@"Quit" target:self selector:@selector(quit:)]; CCMenu *mn = ; ; ;}
return self;
}
@end
]
cocos2d-iphone模板自带的两个文件,×××AppDelegate.h和×××AppDelegate.m,我一直不太明白这两个文件是干嘛的,具体怎么用,也请各位大大顺便解答一下,下面是我这工程的这两个文件(我觉得很可能问题就出在这儿):
×××AppDelegate.h:
[lang=
#import <UIKit/UIKit.h>
@class RootViewController;
@interface JustMine_LayerAppDelegate : NSObject {
UIWindow *window;
RootViewController *viewController;
}
@property (nonatomic, retain) UIWindow *window;
@end
]
***AppDelegate.m:
[lang=
#import “cocos2d.h”
#import “JustMine_LayerAppDelegate.h”
#import “GameConfig.h”
#import “RootViewController.h”
#import “SysMenu.h”
@implementation JustMine_LayerAppDelegate
@synthesize window;
- (void) removeStartupFlicker
{
//
// THIS CODE REMOVES THE STARTUP FLICKER
//
// Uncomment the following code if you Application only supports landscape mode
//
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
// CC_ENABLE_DEFAULT_GL_STATES();
// CGSize size = ;
// CCSprite *sprite = ;
// sprite.position = ccp(size.width/2, size.height/2);
// sprite.rotation = -90;
// ;
// ;
// CC_ENABLE_DEFAULT_GL_STATES();
#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController
}
-
(void) applicationDidFinishLaunching:(UIApplication*)application
{
// Init the window
window = initWithFrame: bounds]];// Try to use CADisplayLink director
// if it fails (SDK < 3.1) use the default director
if( ! )
;CCDirector *director = ;
// Init the View Controller
viewController = initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;//
// 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 ageTurnTransition
//
//
EAGLView *glView =
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];// attach the openglView to the director
;
// // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
// if( ! )
// 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
;
#else
;
#endif
;
;
// make the OpenGLView a child of the view controller
;
// make the View Controller a child of the main window
;
;
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
;
// Removes the startup flicker
;
// Run the intro Scene
runWithScene: ];
}
-
(void)applicationWillResignActive:(UIApplication *)application {
pause];
} -
(void)applicationDidBecomeActive:(UIApplication *)application {
resume];
} -
(void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
purgeCachedData];
}
-(void) applicationDidEnterBackground:(UIApplication*)application {
stopAnimation];
}
-(void) applicationWillEnterForeground:(UIApplication*)application {
startAnimation];
}
-
(void)applicationWillTerminate:(UIApplication *)application {
CCDirector *director = ;removeFromSuperview];
;
;
;
} -
(void)applicationSignificantTimeChange:(UIApplication *)application {
setNextDeltaTimeZero:YES];
} -
(void)dealloc {
release];
;
;
}
@end
]