17. /*
//
// AppDelegate.m
// Demo
//
* Kobold2D™ --- http://www.kobold2d.org
// Created by on 1/14/12.
// Copyright Kawaz 2012. All rights reserved.
//
*
#import "cocos2d.h"
#import "AppDelegate.h"
#import "GameConfig.h"
* Copyright (c) 2010-2011 Steffen Itterheim.
#import "HelloWorldLayer.h"
#import "RootViewController.h"
@implementation AppDelegate
@synthesize window;
- (void) removeStartupFlicker
* Released under MIT License in Germany (LICENSE-Kobold2D.txt).
*/
{
//
// THIS CODE REMOVES THE STARTUP FLICKER
//
// Uncomment the following code if you Application only supports landscape mode
//
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
#import "AppDelegate.h"
// CC_ENABLE_DEFAULT_GL_STATES();
// CCDirector *director = [CCDirector sharedDirector];
// CGSize size = [director winSize];
// CCSprite *sprite = [CCSprite spriteWithFile:@"Default.png"];
// sprite.position = ccp(size.width/2, size.height/2);
// sprite.rotation = -90;
// [sprite visit];
// [[director openGLView] swapBuffers];
@implementation AppDelegate
// CC_ENABLE_DEFAULT_GL_STATES();
#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController
}
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
// Init the window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Try to use CADisplayLink director
// if it fails (SDK < 3.1) use the default director
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
-(void) initializationComplete
{
[CCDirector setDirectorType:kCCDirectorTypeDefault];
CCDirector *director = [CCDirector sharedDirector];
// Init the View Controller
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
#ifdef KK_ARC_ENABLED
//
// Create the EAGLView manually
// 1. Create a RGB565 format. Alternative: RGBA8
CCLOG(@"ARC is enabled");
#else
// 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like
CCPageTurnTransition
//
//
CCLOG(@"ARC is either not available or not enabled");
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
#endif
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] )
-(id) alternateRootViewController
// 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:
return nil;
// 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
[viewController setView:glView];
-(id) alternateView
{
// make the View Controller a child of the main window
[window addSubview: viewController.view];
[window makeKeyAndVisible];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
return nil;
}
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// Removes the startup flicker
[self removeStartupFlicker];
// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];
@end
}
- (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 {
17
CCDirector *director = [CCDirector sharedDirector];
[[director openGLView] removeFromSuperview];
Monday, January 16, 12 [viewController release];
18. local config =
{
KKStartupConfig =
{
-- load first scene from a class with this name, or from a Lua script
with this name with .lua appended
FirstSceneClassName = "HelloWorldLayer",
-- set the director type, and the fallback in case the first isn't
available
DirectorType = DirectorType.DisplayLink,
DirectorTypeFallback = DirectorType.NSTimer,
MaxFrameRate = 60,
DisplayFPS = YES,
EnableUserInteraction = YES,
EnableMultiTouch = NO,
-- ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
}
return config
int fps = [[KKStartupConfig config] maxFrameRate];
18
Monday, January 16, 12
22. -- iAd setup
EnableAdBanner = YES,
PlaceBannerOnBottom = YES,
LoadOnlyPortraitBanners = NO,
LoadOnlyLandscapeBanners = NO,
AdProviders = "iAd, AdMob", -- comma seperated list -> "iAd, AdMob"
means: use iAd if available, otherwise AdMob
AdMobRefreshRate = 15,
AdMobFirstAdDelay = 5,
AdMobPublisherID = "YOUR_ADMOB_PUBLISHER_ID", -- how to get an AdMob
Publisher ID: http://developer.admob.com/wiki/PublisherSetup
AdMobTestMode = YES,
22
Monday, January 16, 12