www.pudn.com > Simple-shooting-game.zip > AppDelegate.m, change:2012-02-07,size:2386b


//
//  AppDelegate.m
//  Cocos2DGame
//
//  Created by Yang QianFeng on 11-12-29.
//  Copyright (c) 2011年 千锋3G www.mobiletrain.org. All rights reserved.
//

#import "AppDelegate.h"
#import "cocos2d.h"
#import "StartScene.h"

@implementation AppDelegate

@synthesize window = _window;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];    
    
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
		[CCDirector setDirectorType:kCCDirectorTypeDefault];
	
	CCDirector *director = [CCDirector sharedDirector];
    
	EAGLView *glView = [EAGLView viewWithFrame:[self.window bounds]
                    pixelFormat:kEAGLColorFormatRGB565	
                    depthFormat:0				
                ];
	

	[director setOpenGLView:glView];

	[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
	
	[director setAnimationInterval:1.0/60];
	[director setDisplayFPS:YES];
	
    [self.window addSubview:glView];
	[self.window makeKeyAndVisible];
	
	[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    
    [[CCDirector sharedDirector] runWithScene:[StartScene scene]];		

    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
	[[CCDirector sharedDirector] pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
	[[CCDirector sharedDirector] resume];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
	[[CCDirector sharedDirector] purgeCachedData];
}

-(void) applicationDidEnterBackground:(UIApplication*)application {
	[[CCDirector sharedDirector] stopAnimation];
}

-(void) applicationWillEnterForeground:(UIApplication*)application {
	[[CCDirector sharedDirector] startAnimation];
}

- (void)applicationWillTerminate:(UIApplication *)application {
	CCDirector *director = [CCDirector sharedDirector];
	
	[[director openGLView] removeFromSuperview];
    
	[_window release];
	
	[director end];	
}

- (void)applicationSignificantTimeChange:(UIApplication *)application {
	[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}

- (void)dealloc
{
    [[CCDirector sharedDirector] release];
    [_window release];
    [super dealloc];
}

@end