Skip to content

Commit

Permalink
Merge pull request kstenerud#1 from mb1/cocos2d-2.0-update
Browse files Browse the repository at this point in the history
Cocos2d 2.0 update
  • Loading branch information
gregharding committed Sep 8, 2012
2 parents 92be2b3 + ea2ff95 commit 79ad0c1
Show file tree
Hide file tree
Showing 291 changed files with 23,364 additions and 13,475 deletions.
1,829 changes: 1,145 additions & 684 deletions ObjectAL.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions ObjectALDemo/AppDelegate.h 100755 → 100644
@@ -1,19 +1,23 @@
//
// AppDelegate.h
// ObjectAL
// ObjectALDemo
//
// Created by Karl Stenerud on 11/23/11.
// Created by Monkey on 7/09/12.
//

#import <UIKit/UIKit.h>
#import "cocos2d.h"

@class RootViewController;
@interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate>
{
UIWindow *window_;
UINavigationController *navController_;

@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *viewController;
CCDirectorIOS *director_; // weak ref
}

@property (nonatomic, retain) UIWindow *window;
@property (readonly) UINavigationController *navController;
@property (readonly) CCDirectorIOS *director;

@end
232 changes: 110 additions & 122 deletions ObjectALDemo/AppDelegate.m 100755 → 100644
@@ -1,165 +1,153 @@
//
// AppDelegate.m
// ObjectAL
// ObjectALDemo
//
// Created by Karl Stenerud on 11/23/11.
// Created by Monkey on 7/09/12.
//

#import "cocos2d.h"

#import "AppDelegate.h"
#import "GameConfig.h"
#import "RootViewController.h"

#import "CCLayer+Scene.h"
#import "MainScene.h"
#import "IntroLayer.h"
#import "ObjectAL.h"

@implementation AppController

@implementation AppDelegate

@synthesize window;
@synthesize window=window_, navController=navController_, director=director_;

- (void) removeStartupFlicker
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//
// 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();
// 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];
// 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] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];


CCDirector *director = [CCDirector sharedDirector];

// Init the View Controller
viewController = [[RootViewController alloc] 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 CCPageTurnTransition
//
//
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];

// Create the main window
window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


// Create an CCGLView with a RGB565 color buffer, and a depth buffer of 0-bits
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8 // kEAGLColorFormatRGB565
depthFormat:0 // GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];

director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

director_.wantsFullScreenLayout = YES;

// Display FSP and SPF
[director_ setDisplayStats:NO];

// set FPS at 60
[director_ setAnimationInterval:1.0/60];

// 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
[viewController setView:glView];

// make the View Controller a child of the main window
[window addSubview: viewController.view];

[window makeKeyAndVisible];

[director_ setView:glView];

// for rotation and other messages
[director_ setDelegate:self];

// 2D projection
[director_ setProjection:kCCDirectorProjection2D];

// 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");

// 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];

// If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
// On iPad HD : "-ipadhd", "-ipad", "-hd"
// On iPad : "-ipad", "-hd"
// On iPhone HD: "-hd"
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"]; // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-ipad"]; // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"]; // Default on iPad RetinaDisplay is "-ipadhd"

// Assume that PVR images have premultiplied alpha
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];

// Kick off audio initialization before our main scene begins.
// Note: This default init will cause OALSimpleAudio to take all 32 sources.
[OALSimpleAudio sharedInstance];
[OALSimpleAudio sharedInstance];

// and add the scene to the stack. The director will run it when it automatically when the view is displayed.
[director_ pushScene: [IntroLayer scene]];

// Create a Navigation Controller with the Director
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;

// set the Navigation Controller as the root view controller
[window_ setRootViewController:navController_];

// make main window visible
[window_ makeKeyAndVisible];

return YES;
}

// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [MainLayer scene]];
// Supported orientations: Landscape. Customize it for your own needs
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}


- (void)applicationWillResignActive:(UIApplication *)application {
[[CCDirector sharedDirector] pause];
// getting a call, pause the game
-(void) applicationWillResignActive:(UIApplication *)application
{
if( [navController_ visibleViewController] == director_ )
[director_ pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
[[CCDirector sharedDirector] resume];
// call got rejected
-(void) applicationDidBecomeActive:(UIApplication *)application
{
if( [navController_ visibleViewController] == director_ )
[director_ resume];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[CCDirector sharedDirector] purgeCachedData];
-(void) applicationDidEnterBackground:(UIApplication*)application
{
if( [navController_ visibleViewController] == director_ )
[director_ stopAnimation];
}

-(void) applicationDidEnterBackground:(UIApplication*)application {
[[CCDirector sharedDirector] stopAnimation];
-(void) applicationWillEnterForeground:(UIApplication*)application
{
if( [navController_ visibleViewController] == director_ )
[director_ startAnimation];
}

-(void) applicationWillEnterForeground:(UIApplication*)application {
[[CCDirector sharedDirector] startAnimation];
// application will be killed
- (void)applicationWillTerminate:(UIApplication *)application
{
CC_DIRECTOR_END();
}

- (void)applicationWillTerminate:(UIApplication *)application {
CCDirector *director = [CCDirector sharedDirector];

[[director openGLView] removeFromSuperview];

[viewController release];

[window release];

[director end];
// purge memory
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
[[CCDirector sharedDirector] purgeCachedData];
}

- (void)applicationSignificantTimeChange:(UIApplication *)application {
// next delta time will be zero
-(void) applicationSignificantTimeChange:(UIApplication *)application
{
[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}

- (void)dealloc {
[[CCDirector sharedDirector] end];
[window release];
- (void) dealloc
{
[window_ release];
[navController_ release];

[super dealloc];
}

@end

1 change: 1 addition & 0 deletions ObjectALDemo/Demos/AudioTrackDemo.m
Expand Up @@ -8,6 +8,7 @@
#import "AudioTrackDemo.h"
#import "MainScene.h"
#import "CCLayer+Scene.h"
#import "ImageButton.h"
#import "ImageAndLabelButton.h"
#import "Slider.h"
#import "ObjectAL.h"
Expand Down
44 changes: 0 additions & 44 deletions ObjectALDemo/GameConfig.h

This file was deleted.

20 changes: 20 additions & 0 deletions ObjectALDemo/IntroLayer.h
@@ -0,0 +1,20 @@
//
// IntroLayer.h
// ObjectALDemo
//
// Created by Monkey on 7/09/12.
//


// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"

// HelloWorldLayer
@interface IntroLayer : CCLayer
{
}

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;

@end

0 comments on commit 79ad0c1

Please sign in to comment.