From 06f014604add5aca3f24e50770e36911657c54b5 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 10 Mar 2011 11:59:17 +0800 Subject: [PATCH] [iOS] fixed #388 --- install-templates.sh | 2 +- .../cocos2d-x_app/Classes/HelloWorldScene.cpp | 15 +-- .../cocos2d-x_app/Classes/HelloWorldScene.h | 9 +- ..._PROJECTNAMEASIDENTIFIER___AppController.h | 14 +++ ...PROJECTNAMEASIDENTIFIER___AppController.mm | 98 ++++++++++++++++ ..._PROJECTNAMEASIDENTIFIER___AppDelegate.cpp | 106 ++++++++++++++++++ ...___PROJECTNAMEASIDENTIFIER___AppDelegate.h | 51 +++++++++ ...___PROJECTNAMEASIDENTIFIER___AppDelegate.h | 22 ---- ...__PROJECTNAMEASIDENTIFIER___AppDelegate.mm | 98 ---------------- .../project.pbxproj.REMOVED.git-id | 2 +- template/ios_mac/cocos2d-x_app/main.m | 2 +- .../Classes/HelloWorldScene.cpp | 20 ++-- .../Classes/HelloWorldScene.h | 4 +- ..._PROJECTNAMEASIDENTIFIER___AppController.h | 14 +++ ...PROJECTNAMEASIDENTIFIER___AppController.mm | 98 ++++++++++++++++ ..._PROJECTNAMEASIDENTIFIER___AppDelegate.cpp | 106 ++++++++++++++++++ ...___PROJECTNAMEASIDENTIFIER___AppDelegate.h | 51 +++++++++ ...___PROJECTNAMEASIDENTIFIER___AppDelegate.h | 22 ---- ...__PROJECTNAMEASIDENTIFIER___AppDelegate.mm | 98 ---------------- .../project.pbxproj.REMOVED.git-id | 2 +- template/ios_mac/cocos2d-x_box2d_app/main.m | 2 +- .../Classes/HelloWorldScene.cpp | 12 +- .../Classes/HelloWorldScene.h | 2 +- ..._PROJECTNAMEASIDENTIFIER___AppController.h | 14 +++ ...PROJECTNAMEASIDENTIFIER___AppController.mm | 98 ++++++++++++++++ ..._PROJECTNAMEASIDENTIFIER___AppDelegate.cpp | 106 ++++++++++++++++++ ...___PROJECTNAMEASIDENTIFIER___AppDelegate.h | 51 +++++++++ ...___PROJECTNAMEASIDENTIFIER___AppDelegate.h | 22 ---- ...__PROJECTNAMEASIDENTIFIER___AppDelegate.mm | 98 ---------------- .../project.pbxproj.REMOVED.git-id | 2 +- .../ios_mac/cocos2d-x_chipmunk_app/main.m | 2 +- 31 files changed, 846 insertions(+), 397 deletions(-) mode change 100755 => 100644 template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.cpp mode change 100755 => 100644 template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.h create mode 100644 template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h create mode 100644 template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm create mode 100644 template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp create mode 100644 template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h delete mode 100755 template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h delete mode 100755 template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm create mode 100644 template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h create mode 100644 template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm create mode 100644 template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp create mode 100644 template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h delete mode 100755 template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h delete mode 100755 template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm create mode 100644 template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h create mode 100644 template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm create mode 100644 template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp create mode 100644 template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h delete mode 100755 template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h delete mode 100755 template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm diff --git a/install-templates.sh b/install-templates.sh index 82a4a8d18b..7aaf156ff5 100644 --- a/install-templates.sh +++ b/install-templates.sh @@ -2,7 +2,7 @@ echo 'cocos2d-x template installer' -COCOS2D_VER='cocos2d-0.99.5-x-0.7.2' +COCOS2D_VER='cocos2d-0.99.5-x-0.8.0' BASE_TEMPLATE_DIR="/Library/Application Support/Developer/Shared/Xcode" BASE_TEMPLATE_USER_DIR="$HOME/Library/Application Support/Developer/Shared/Xcode" diff --git a/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.cpp b/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.cpp old mode 100755 new mode 100644 index 9fc577deb8..46a44ae3b2 --- a/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.cpp +++ b/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.cpp @@ -5,9 +5,10 @@ // Created by ___FULLUSERNAME___ on ___DATE___. // Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. // + #include "HelloWorldScene.h" -using namespace cocos2d; +USING_NS_CC; CCScene* HelloWorld::scene() { @@ -48,7 +49,7 @@ bool HelloWorld::init() // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL); - pMenu->setPosition( CGPointZero ); + pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); ///////////////////////////// @@ -56,10 +57,10 @@ bool HelloWorld::init() // add a label shows "Hello World" // create and initialize a label - CCLabelTTF* pLabel = CCLabelTTF::labelWithString("HelloWorld", "Thonburi", 34); + CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 34); // ask director the window size - CGSize size = CCDirector::sharedDirector()->getWinSize(); + CCSize size = CCDirector::sharedDirector()->getWinSize(); // position the label on the center of the screen pLabel->setPosition( ccp(size.width / 2, size.height - 20) ); @@ -73,13 +74,13 @@ bool HelloWorld::init() // position the sprite on the center of the screen pSprite->setPosition( ccp(size.width/2, size.height/2) ); - // ad the sprite as a child to this layer + // add the sprite as a child to this layer this->addChild(pSprite, 0); return true; } -void HelloWorld::menuCloseCallback(NSObject* pSender) +void HelloWorld::menuCloseCallback(CCObject* pSender) { CCDirector::sharedDirector()->end(); -} \ No newline at end of file +} diff --git a/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.h b/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.h old mode 100755 new mode 100644 index c704b7bf82..29f78e0be1 --- a/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.h +++ b/template/ios_mac/cocos2d-x_app/Classes/HelloWorldScene.h @@ -5,8 +5,9 @@ // Created by ___FULLUSERNAME___ on ___DATE___. // Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. // -#ifndef _HELLOWORLD_LAYER_H_ -#define _HELLOWORLD_LAYER_H_ + +#ifndef __HELLOWORLD_SCENE_H__ +#define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" @@ -20,10 +21,10 @@ public: static cocos2d::CCScene* scene(); // a selector callback - virtual void menuCloseCallback(NSObject* pSender); + virtual void menuCloseCallback(CCObject* pSender); // implement the "static node()" method manually LAYER_NODE_FUNC(HelloWorld); }; -#endif // _HELLOWORLD_SCENE_H_ \ No newline at end of file +#endif // __HELLOWORLD_SCENE_H__ diff --git a/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h new file mode 100644 index 0000000000..6a407a9375 --- /dev/null +++ b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h @@ -0,0 +1,14 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppController.h +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +@interface ___PROJECTNAMEASIDENTIFIER___AppController : NSObject { + UIWindow *window; +} + +@end + diff --git a/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm new file mode 100644 index 0000000000..ba2ec925c5 --- /dev/null +++ b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm @@ -0,0 +1,98 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppController.mm +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// +#import +#import "___PROJECTNAMEASIDENTIFIER___AppController.h" +#import "cocos2d.h" +#import "EAGLView.h" +#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" + +@implementation ___PROJECTNAMEASIDENTIFIER___AppController + +#pragma mark - +#pragma mark Application lifecycle + +// cocos2d application instance +static AppDelegate s_sharedApplication; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + // Override point for customization after application launch. + + // Add the view controller's view to the window and display. + window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; + EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] + pixelFormat: kEAGLColorFormatRGBA8 + depthFormat: 0 + preserveBackbuffer: NO + sharegroup:nil + multiSampling:NO + numberOfSamples:0]; + [window addSubview: __glView]; + [window makeKeyAndVisible]; + + [[UIApplication sharedApplication] setStatusBarHidden: YES]; + + cocos2d::CCApplication::sharedApplication().run(); + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + /* + Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + */ +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + /* + Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + If your application supports background execution, called instead of applicationWillTerminate: when the user quits. + */ +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + /* + Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. + */ +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + /* + Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + */ +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + /* + Called when the application is about to terminate. + See also applicationDidEnterBackground:. + */ +} + + +#pragma mark - +#pragma mark Memory management + +- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { + /* + Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. + */ +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end diff --git a/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp new file mode 100644 index 0000000000..a2cb2b2306 --- /dev/null +++ b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp @@ -0,0 +1,106 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +#include "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" + +#include "cocos2d.h" +#include "HelloWorldScene.h" + +USING_NS_CC; + +AppDelegate::AppDelegate() +{ + +} + +AppDelegate::~AppDelegate() +{ +} + +bool AppDelegate::initInstance() +{ + bool bRet = false; + do + { +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + + // Initialize OpenGLView instance, that release by CCDirector when application terminate. + // The HelloWorld is designed as HVGA. + CCEGLView * pMainWnd = new CCEGLView(); + CC_BREAK_IF(! pMainWnd + || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 320, 480)); + +#endif // CC_PLATFORM_WIN32 + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + // OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here. +#endif // CC_PLATFORM_IOS + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE) + + // Initialize OpenGLView instance, that release by CCDirector when application terminate. + // The HelloWorld is designed as HVGA. + CCEGLView* pMainWnd = new CCEGLView(this); + CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480)); + +#ifndef _TRANZDA_VM_ + // on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file + cocos2d::CCFileUtils::setResource("HelloWorld.zip"); +#endif + +#endif // CC_PLATFORM_WOPHONE + + bRet = true; + } while (0); + return bRet; +} + +bool AppDelegate::applicationDidFinishLaunching() +{ + // initialize director + CCDirector *pDirector = CCDirector::sharedDirector(); + pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); + + // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. +// pDirector->enableRetinaDisplay(true); + + // sets landscape mode + pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); + + // turn on display FPS + pDirector->setDisplayFPS(true); + + // set FPS. the default value is 1.0/60 if you don't call this + pDirector->setAnimationInterval(1.0 / 60); + + // create a scene. it's an autorelease object + CCScene *pScene = HelloWorld::scene(); + + // run + pDirector->runWithScene(pScene); + + return true; +} + +// This function will be called when the app is inactive. When comes a phone call,it's be invoked too +void AppDelegate::applicationDidEnterBackground() +{ + CCDirector::sharedDirector()->pause(); + + // if you use SimpleAudioEngine, it must be pause + // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); +} + +// this function will be called when the app is active again +void AppDelegate::applicationWillEnterForeground() +{ + CCDirector::sharedDirector()->resume(); + + // if you use SimpleAudioEngine, it must resume here + // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); +} diff --git a/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h new file mode 100644 index 0000000000..3161a11d65 --- /dev/null +++ b/template/ios_mac/cocos2d-x_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h @@ -0,0 +1,51 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +#ifndef _APP_DELEGATE_H_ +#define _APP_DELEGATE_H_ + +#include "CCApplication.h" + +/** +@brief The cocos2d Application. + +The reason for implement as private inheritance is to hide some interface call by CCDirector. +*/ +class AppDelegate : private cocos2d::CCApplication +{ +public: + AppDelegate(); + virtual ~AppDelegate(); + + /** + @brief Implement for initialize OpenGL instance, set source path, etc... + */ + virtual bool initInstance(); + + /** + @brief Implement CCDirector and CCScene init code here. + @return true Initialize success, app continue. + @return false Initialize failed, app terminate. + */ + virtual bool applicationDidFinishLaunching(); + + /** + @brief The function be called when the application enter background + @param the pointer of the application + */ + virtual void applicationDidEnterBackground(); + + /** + @brief The function be called when the application enter foreground + @param the pointer of the application + */ + virtual void applicationWillEnterForeground(); +}; + +#endif // _APP_DELEGATE_H_ + diff --git a/template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h b/template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h deleted file mode 100755 index cf42725b33..0000000000 --- a/template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h -// ___PROJECTNAME___ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// - -#import -#import "cocos2d.h" - -@class RootViewController; - -@interface ___PROJECTNAMEASIDENTIFIER___AppDelegate : NSObject { - UIWindow *window; - RootViewController *viewController; - cocos2d::CCXEGLView *view; -} - -@property (nonatomic, retain) UIWindow *window; - -@end diff --git a/template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm b/template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm deleted file mode 100755 index ec89c8241f..0000000000 --- a/template/ios_mac/cocos2d-x_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm +++ /dev/null @@ -1,98 +0,0 @@ - // - // apptestAppDelegate.m - // apptest - // - // Created by Walzer on 11-1-17. - // Copyright __MyCompanyName__ 2011. All rights reserved. - // - -#import "EAGLView.h" -#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" -#import "HelloWorldScene.h" -#import "platform/iphone/CCDirectorCaller.h" - -@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate - -@synthesize window; - -- (void) applicationDidFinishLaunching:(UIApplication*)application -{ - window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; - EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] - pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: 0 - preserveBackbuffer: NO - sharegroup:nil - multiSampling:NO - numberOfSamples:0]; - [__glView setMultipleTouchEnabled:YES]; - [window addSubview: __glView]; - [window makeKeyAndVisible]; - - [[UIApplication sharedApplication] setStatusBarHidden: YES]; - - // // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices - // if (! CCDirector::sharedDirector()->enableRetinaDisplay(true)) { - // CCLOG("Retina Display Not supported"); - // } - - // init director - view = new cocos2d::CCXEGLView(); - cocos2d::CCDirector *pDirector = cocos2d::CCDirector::sharedDirector(); - pDirector->setOpenGLView(view); - - cocos2d::CCDirector::sharedDirector()->setDeviceOrientation(cocos2d::kCCDeviceOrientationLandscapeLeft); - - // turn on display FPS - pDirector->setDisplayFPS(true); - - // create a scene. it's an autorelease object - cocos2d::CCScene *pScene = HelloWorld::scene(); - - // run - pDirector->runWithScene(pScene); - - // start mainloop - [[CCDirectorCaller sharedDirectorCaller] startMainLoop]; -} - - -- (void)applicationWillResignActive:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->resume(); -} - -- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->purgeCachedData(); -} - --(void) applicationDidEnterBackground:(UIApplication*)application { - cocos2d::CCDirector::sharedDirector()->stopAnimation(); -} - --(void) applicationWillEnterForeground:(UIApplication*)application { - cocos2d::CCDirector::sharedDirector()->startAnimation(); -} - -- (void)applicationWillTerminate:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->end(); - - [viewController release]; - - [window release]; -} - -- (void)applicationSignificantTimeChange:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->setNextDeltaTimeZero(true); -} - -- (void)dealloc { - delete view; - [window release]; - [super dealloc]; -} - -@end diff --git a/template/ios_mac/cocos2d-x_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id b/template/ios_mac/cocos2d-x_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id index 1a5d72a397..1ca35ce9d3 100644 --- a/template/ios_mac/cocos2d-x_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/template/ios_mac/cocos2d-x_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -8eaad60733877a3f984c20062f8e7b3ca4dfdd5c \ No newline at end of file +d3596594374bce613ec48e387957b90f74edc9d9 \ No newline at end of file diff --git a/template/ios_mac/cocos2d-x_app/main.m b/template/ios_mac/cocos2d-x_app/main.m index a42b040336..106d54c93e 100755 --- a/template/ios_mac/cocos2d-x_app/main.m +++ b/template/ios_mac/cocos2d-x_app/main.m @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppDelegate"); + int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppController"); [pool release]; return retVal; } diff --git a/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.cpp b/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.cpp index 813bcdb874..2bded2e0e9 100755 --- a/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.cpp +++ b/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.cpp @@ -22,7 +22,7 @@ HelloWorld::HelloWorld() setIsTouchEnabled( true ); setIsAccelerometerEnabled( true ); - CGSize screenSize = CCDirector::sharedDirector()->getWinSize(); + CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); //UXLOG(L"Screen width %0.2f screen height %0.2f",screenSize.width,screenSize.height); // Define the gravity vector. @@ -84,12 +84,12 @@ HelloWorld::HelloWorld() CCSpriteBatchNode *mgr = CCSpriteBatchNode::spriteSheetWithFile("blocks.png", 150); addChild(mgr, 0, kTagSpriteManager); - addNewSpriteWithCoords( CGPointMake(screenSize.width/2, screenSize.height/2) ); + addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2) ); CCLabelTTF *label = CCLabelTTF::labelWithString("Tap screen", "Marker Felt", 32); addChild(label, 0); label->setColor( ccc3(0,0,255) ); - label->setPosition( CGPointMake( screenSize.width/2, screenSize.height-50) ); + label->setPosition( CCPointMake( screenSize.width/2, screenSize.height-50) ); schedule( schedule_selector(HelloWorld::tick) ); } @@ -119,7 +119,7 @@ void HelloWorld::draw() glEnableClientState(GL_TEXTURE_COORD_ARRAY); } -void HelloWorld::addNewSpriteWithCoords(CGPoint p) +void HelloWorld::addNewSpriteWithCoords(CCPoint p) { //UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y); CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager); @@ -128,10 +128,10 @@ void HelloWorld::addNewSpriteWithCoords(CGPoint p) //just randomly picking one of the images int idx = (CCRANDOM_0_1() > .5 ? 0:1); int idy = (CCRANDOM_0_1() > .5 ? 0:1); - CCSprite *sprite = sheet->createSpriteWithRect( CGRectMake(32 * idx,32 * idy,32,32)); + CCSprite *sprite = sheet->createSpriteWithRect( CCRectMake(32 * idx,32 * idy,32,32)); sheet->addChild(sprite); - sprite->setPosition( CGPointMake( p.x, p.y) ); + sprite->setPosition( CCPointMake( p.x, p.y) ); // Define the dynamic body. //Set up a 1m squared box in the physics world @@ -174,16 +174,16 @@ void HelloWorld::tick(ccTime dt) if (b->GetUserData() != NULL) { //Synchronize the AtlasSprites position and rotation with the corresponding body CCSprite* myActor = (CCSprite*)b->GetUserData(); - myActor->setPosition( CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO) ); + myActor->setPosition( CCPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO) ); myActor->setRotation( -1 * CC_RADIANS_TO_DEGREES(b->GetAngle()) ); } } } -void HelloWorld::ccTouchesEnded(NSSet* touches, UIEvent* event) +void HelloWorld::ccTouchesEnded(CCSet* touches, UIEvent* event) { //Add a new body/atlas sprite at the touched location - NSSetIterator it; + CCSetIterator it; CCTouch* touch; for( it = touches->begin(); it != touches->end(); it++) @@ -193,7 +193,7 @@ void HelloWorld::ccTouchesEnded(NSSet* touches, UIEvent* event) if(!touch) break; - CGPoint location = touch->locationInView(touch->view()); + CCPoint location = touch->locationInView(touch->view()); location = CCDirector::sharedDirector()->convertToGL(location); diff --git a/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.h b/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.h index 0966ca1a1c..50f160ff47 100755 --- a/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.h +++ b/template/ios_mac/cocos2d-x_box2d_app/Classes/HelloWorldScene.h @@ -21,9 +21,9 @@ public: static cocos2d::CCScene* scene(); // adds a new sprite at a given coordinate - void addNewSpriteWithCoords(cocos2d::CGPoint p); + void addNewSpriteWithCoords(cocos2d::CCPoint p); virtual void draw(); - virtual void ccTouchesEnded(cocos2d::NSSet* touches, cocos2d::UIEvent* event); + virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::UIEvent* event); void tick(cocos2d::ccTime dt); private: diff --git a/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h new file mode 100644 index 0000000000..6a407a9375 --- /dev/null +++ b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h @@ -0,0 +1,14 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppController.h +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +@interface ___PROJECTNAMEASIDENTIFIER___AppController : NSObject { + UIWindow *window; +} + +@end + diff --git a/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm new file mode 100644 index 0000000000..ba2ec925c5 --- /dev/null +++ b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm @@ -0,0 +1,98 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppController.mm +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// +#import +#import "___PROJECTNAMEASIDENTIFIER___AppController.h" +#import "cocos2d.h" +#import "EAGLView.h" +#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" + +@implementation ___PROJECTNAMEASIDENTIFIER___AppController + +#pragma mark - +#pragma mark Application lifecycle + +// cocos2d application instance +static AppDelegate s_sharedApplication; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + // Override point for customization after application launch. + + // Add the view controller's view to the window and display. + window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; + EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] + pixelFormat: kEAGLColorFormatRGBA8 + depthFormat: 0 + preserveBackbuffer: NO + sharegroup:nil + multiSampling:NO + numberOfSamples:0]; + [window addSubview: __glView]; + [window makeKeyAndVisible]; + + [[UIApplication sharedApplication] setStatusBarHidden: YES]; + + cocos2d::CCApplication::sharedApplication().run(); + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + /* + Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + */ +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + /* + Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + If your application supports background execution, called instead of applicationWillTerminate: when the user quits. + */ +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + /* + Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. + */ +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + /* + Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + */ +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + /* + Called when the application is about to terminate. + See also applicationDidEnterBackground:. + */ +} + + +#pragma mark - +#pragma mark Memory management + +- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { + /* + Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. + */ +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end diff --git a/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp new file mode 100644 index 0000000000..a2cb2b2306 --- /dev/null +++ b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp @@ -0,0 +1,106 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +#include "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" + +#include "cocos2d.h" +#include "HelloWorldScene.h" + +USING_NS_CC; + +AppDelegate::AppDelegate() +{ + +} + +AppDelegate::~AppDelegate() +{ +} + +bool AppDelegate::initInstance() +{ + bool bRet = false; + do + { +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + + // Initialize OpenGLView instance, that release by CCDirector when application terminate. + // The HelloWorld is designed as HVGA. + CCEGLView * pMainWnd = new CCEGLView(); + CC_BREAK_IF(! pMainWnd + || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 320, 480)); + +#endif // CC_PLATFORM_WIN32 + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + // OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here. +#endif // CC_PLATFORM_IOS + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE) + + // Initialize OpenGLView instance, that release by CCDirector when application terminate. + // The HelloWorld is designed as HVGA. + CCEGLView* pMainWnd = new CCEGLView(this); + CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480)); + +#ifndef _TRANZDA_VM_ + // on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file + cocos2d::CCFileUtils::setResource("HelloWorld.zip"); +#endif + +#endif // CC_PLATFORM_WOPHONE + + bRet = true; + } while (0); + return bRet; +} + +bool AppDelegate::applicationDidFinishLaunching() +{ + // initialize director + CCDirector *pDirector = CCDirector::sharedDirector(); + pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); + + // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. +// pDirector->enableRetinaDisplay(true); + + // sets landscape mode + pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); + + // turn on display FPS + pDirector->setDisplayFPS(true); + + // set FPS. the default value is 1.0/60 if you don't call this + pDirector->setAnimationInterval(1.0 / 60); + + // create a scene. it's an autorelease object + CCScene *pScene = HelloWorld::scene(); + + // run + pDirector->runWithScene(pScene); + + return true; +} + +// This function will be called when the app is inactive. When comes a phone call,it's be invoked too +void AppDelegate::applicationDidEnterBackground() +{ + CCDirector::sharedDirector()->pause(); + + // if you use SimpleAudioEngine, it must be pause + // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); +} + +// this function will be called when the app is active again +void AppDelegate::applicationWillEnterForeground() +{ + CCDirector::sharedDirector()->resume(); + + // if you use SimpleAudioEngine, it must resume here + // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); +} diff --git a/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h new file mode 100644 index 0000000000..3161a11d65 --- /dev/null +++ b/template/ios_mac/cocos2d-x_box2d_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h @@ -0,0 +1,51 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +#ifndef _APP_DELEGATE_H_ +#define _APP_DELEGATE_H_ + +#include "CCApplication.h" + +/** +@brief The cocos2d Application. + +The reason for implement as private inheritance is to hide some interface call by CCDirector. +*/ +class AppDelegate : private cocos2d::CCApplication +{ +public: + AppDelegate(); + virtual ~AppDelegate(); + + /** + @brief Implement for initialize OpenGL instance, set source path, etc... + */ + virtual bool initInstance(); + + /** + @brief Implement CCDirector and CCScene init code here. + @return true Initialize success, app continue. + @return false Initialize failed, app terminate. + */ + virtual bool applicationDidFinishLaunching(); + + /** + @brief The function be called when the application enter background + @param the pointer of the application + */ + virtual void applicationDidEnterBackground(); + + /** + @brief The function be called when the application enter foreground + @param the pointer of the application + */ + virtual void applicationWillEnterForeground(); +}; + +#endif // _APP_DELEGATE_H_ + diff --git a/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h b/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h deleted file mode 100755 index cf42725b33..0000000000 --- a/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h -// ___PROJECTNAME___ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// - -#import -#import "cocos2d.h" - -@class RootViewController; - -@interface ___PROJECTNAMEASIDENTIFIER___AppDelegate : NSObject { - UIWindow *window; - RootViewController *viewController; - cocos2d::CCXEGLView *view; -} - -@property (nonatomic, retain) UIWindow *window; - -@end diff --git a/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm b/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm deleted file mode 100755 index ec89c8241f..0000000000 --- a/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm +++ /dev/null @@ -1,98 +0,0 @@ - // - // apptestAppDelegate.m - // apptest - // - // Created by Walzer on 11-1-17. - // Copyright __MyCompanyName__ 2011. All rights reserved. - // - -#import "EAGLView.h" -#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" -#import "HelloWorldScene.h" -#import "platform/iphone/CCDirectorCaller.h" - -@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate - -@synthesize window; - -- (void) applicationDidFinishLaunching:(UIApplication*)application -{ - window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; - EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] - pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: 0 - preserveBackbuffer: NO - sharegroup:nil - multiSampling:NO - numberOfSamples:0]; - [__glView setMultipleTouchEnabled:YES]; - [window addSubview: __glView]; - [window makeKeyAndVisible]; - - [[UIApplication sharedApplication] setStatusBarHidden: YES]; - - // // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices - // if (! CCDirector::sharedDirector()->enableRetinaDisplay(true)) { - // CCLOG("Retina Display Not supported"); - // } - - // init director - view = new cocos2d::CCXEGLView(); - cocos2d::CCDirector *pDirector = cocos2d::CCDirector::sharedDirector(); - pDirector->setOpenGLView(view); - - cocos2d::CCDirector::sharedDirector()->setDeviceOrientation(cocos2d::kCCDeviceOrientationLandscapeLeft); - - // turn on display FPS - pDirector->setDisplayFPS(true); - - // create a scene. it's an autorelease object - cocos2d::CCScene *pScene = HelloWorld::scene(); - - // run - pDirector->runWithScene(pScene); - - // start mainloop - [[CCDirectorCaller sharedDirectorCaller] startMainLoop]; -} - - -- (void)applicationWillResignActive:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->resume(); -} - -- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->purgeCachedData(); -} - --(void) applicationDidEnterBackground:(UIApplication*)application { - cocos2d::CCDirector::sharedDirector()->stopAnimation(); -} - --(void) applicationWillEnterForeground:(UIApplication*)application { - cocos2d::CCDirector::sharedDirector()->startAnimation(); -} - -- (void)applicationWillTerminate:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->end(); - - [viewController release]; - - [window release]; -} - -- (void)applicationSignificantTimeChange:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->setNextDeltaTimeZero(true); -} - -- (void)dealloc { - delete view; - [window release]; - [super dealloc]; -} - -@end diff --git a/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id b/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id index dd4ce7a6c2..1fa33630d7 100644 --- a/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/template/ios_mac/cocos2d-x_box2d_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -86485d992dea618d4513528e3a102cce15955c49 \ No newline at end of file +122eb7675b009762b0fd59ff68564bddd57c9d0a \ No newline at end of file diff --git a/template/ios_mac/cocos2d-x_box2d_app/main.m b/template/ios_mac/cocos2d-x_box2d_app/main.m index a42b040336..106d54c93e 100755 --- a/template/ios_mac/cocos2d-x_box2d_app/main.m +++ b/template/ios_mac/cocos2d-x_box2d_app/main.m @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppDelegate"); + int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppController"); [pool release]; return retVal; } diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.cpp b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.cpp index 1ac4b95153..92c204d6b5 100755 --- a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.cpp +++ b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.cpp @@ -27,7 +27,7 @@ eachShape(void *ptr, void* unused) // TIP: cocos2d and chipmunk uses the same struct to store it's position // chipmunk uses: cpVect, and cocos2d uses CGPoint but in reality the are the same // since v0.7.1 you can mix them if you want. - sprite->setPosition(CGPointMake(body->p.x, body->p.y)); + sprite->setPosition(CCPointMake(body->p.x, body->p.y)); sprite->setRotation((float) CC_RADIANS_TO_DEGREES( -body->a )); } @@ -69,7 +69,7 @@ void HelloWorld::addNewSpriteX(float x, float y) posx = (posx % 4) * 85; posy = (posy % 3) * 121; - CCSprite *sprite = CCSprite::spriteWithBatchNode(batch, CGRectMake(posx, posy, 85, 121)); + CCSprite *sprite = CCSprite::spriteWithBatchNode(batch, CCRectMake(posx, posy, 85, 121)); batch->addChild(sprite); sprite->setPosition(ccp(x, y)); @@ -104,7 +104,7 @@ bool HelloWorld::init() { setIsTouchEnabled(true); - CGSize wins = CCDirector::sharedDirector()->getWinSize(); + CCSize wins = CCDirector::sharedDirector()->getWinSize(); cpInitChipmunk(); cpBody *staticBody = cpBodyNew(INFINITY, INFINITY); @@ -167,9 +167,9 @@ void HelloWorld::step(ccTime delta) } -void HelloWorld::ccTouchesEnded(NSSet *touches, UIEvent *event) +void HelloWorld::ccTouchesEnded(CCSet *touches, UIEvent *event) { - NSSetIterator it; + CCSetIterator it; CCTouch *touch; for (it = touches->begin(); it != touches->end(); it++) { @@ -179,7 +179,7 @@ void HelloWorld::ccTouchesEnded(NSSet *touches, UIEvent *event) break; } - CGPoint location = touch->locationInView(touch->view()); + CCPoint location = touch->locationInView(touch->view()); location = CCDirector::sharedDirector()->convertToGL(location); addNewSpriteX(location.x, location.y); } diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.h b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.h index fa7f76eadd..870f1d4062 100755 --- a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.h +++ b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/HelloWorldScene.h @@ -24,7 +24,7 @@ public: void step(cocos2d::ccTime dt); void addNewSpriteX(float x, float y); virtual void onEnter(); - virtual void ccTouchesEnded(cocos2d::NSSet* touches, cocos2d::UIEvent *event); + virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::UIEvent *event); LAYER_NODE_FUNC(HelloWorld); diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h new file mode 100644 index 0000000000..6a407a9375 --- /dev/null +++ b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.h @@ -0,0 +1,14 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppController.h +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +@interface ___PROJECTNAMEASIDENTIFIER___AppController : NSObject { + UIWindow *window; +} + +@end + diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm new file mode 100644 index 0000000000..ba2ec925c5 --- /dev/null +++ b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppController.mm @@ -0,0 +1,98 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppController.mm +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// +#import +#import "___PROJECTNAMEASIDENTIFIER___AppController.h" +#import "cocos2d.h" +#import "EAGLView.h" +#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" + +@implementation ___PROJECTNAMEASIDENTIFIER___AppController + +#pragma mark - +#pragma mark Application lifecycle + +// cocos2d application instance +static AppDelegate s_sharedApplication; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + // Override point for customization after application launch. + + // Add the view controller's view to the window and display. + window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; + EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] + pixelFormat: kEAGLColorFormatRGBA8 + depthFormat: 0 + preserveBackbuffer: NO + sharegroup:nil + multiSampling:NO + numberOfSamples:0]; + [window addSubview: __glView]; + [window makeKeyAndVisible]; + + [[UIApplication sharedApplication] setStatusBarHidden: YES]; + + cocos2d::CCApplication::sharedApplication().run(); + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + /* + Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + */ +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + /* + Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + If your application supports background execution, called instead of applicationWillTerminate: when the user quits. + */ +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + /* + Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. + */ +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + /* + Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + */ +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + /* + Called when the application is about to terminate. + See also applicationDidEnterBackground:. + */ +} + + +#pragma mark - +#pragma mark Memory management + +- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { + /* + Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. + */ +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp new file mode 100644 index 0000000000..a2cb2b2306 --- /dev/null +++ b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp @@ -0,0 +1,106 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +#include "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" + +#include "cocos2d.h" +#include "HelloWorldScene.h" + +USING_NS_CC; + +AppDelegate::AppDelegate() +{ + +} + +AppDelegate::~AppDelegate() +{ +} + +bool AppDelegate::initInstance() +{ + bool bRet = false; + do + { +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + + // Initialize OpenGLView instance, that release by CCDirector when application terminate. + // The HelloWorld is designed as HVGA. + CCEGLView * pMainWnd = new CCEGLView(); + CC_BREAK_IF(! pMainWnd + || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 320, 480)); + +#endif // CC_PLATFORM_WIN32 + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + // OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here. +#endif // CC_PLATFORM_IOS + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE) + + // Initialize OpenGLView instance, that release by CCDirector when application terminate. + // The HelloWorld is designed as HVGA. + CCEGLView* pMainWnd = new CCEGLView(this); + CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480)); + +#ifndef _TRANZDA_VM_ + // on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file + cocos2d::CCFileUtils::setResource("HelloWorld.zip"); +#endif + +#endif // CC_PLATFORM_WOPHONE + + bRet = true; + } while (0); + return bRet; +} + +bool AppDelegate::applicationDidFinishLaunching() +{ + // initialize director + CCDirector *pDirector = CCDirector::sharedDirector(); + pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); + + // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. +// pDirector->enableRetinaDisplay(true); + + // sets landscape mode + pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); + + // turn on display FPS + pDirector->setDisplayFPS(true); + + // set FPS. the default value is 1.0/60 if you don't call this + pDirector->setAnimationInterval(1.0 / 60); + + // create a scene. it's an autorelease object + CCScene *pScene = HelloWorld::scene(); + + // run + pDirector->runWithScene(pScene); + + return true; +} + +// This function will be called when the app is inactive. When comes a phone call,it's be invoked too +void AppDelegate::applicationDidEnterBackground() +{ + CCDirector::sharedDirector()->pause(); + + // if you use SimpleAudioEngine, it must be pause + // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); +} + +// this function will be called when the app is active again +void AppDelegate::applicationWillEnterForeground() +{ + CCDirector::sharedDirector()->resume(); + + // if you use SimpleAudioEngine, it must resume here + // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); +} diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h new file mode 100644 index 0000000000..3161a11d65 --- /dev/null +++ b/template/ios_mac/cocos2d-x_chipmunk_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h @@ -0,0 +1,51 @@ +// +// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h +// ___PROJECTNAME___ +// +// Created by ___FULLUSERNAME___ on ___DATE___. +// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. +// + +#ifndef _APP_DELEGATE_H_ +#define _APP_DELEGATE_H_ + +#include "CCApplication.h" + +/** +@brief The cocos2d Application. + +The reason for implement as private inheritance is to hide some interface call by CCDirector. +*/ +class AppDelegate : private cocos2d::CCApplication +{ +public: + AppDelegate(); + virtual ~AppDelegate(); + + /** + @brief Implement for initialize OpenGL instance, set source path, etc... + */ + virtual bool initInstance(); + + /** + @brief Implement CCDirector and CCScene init code here. + @return true Initialize success, app continue. + @return false Initialize failed, app terminate. + */ + virtual bool applicationDidFinishLaunching(); + + /** + @brief The function be called when the application enter background + @param the pointer of the application + */ + virtual void applicationDidEnterBackground(); + + /** + @brief The function be called when the application enter foreground + @param the pointer of the application + */ + virtual void applicationWillEnterForeground(); +}; + +#endif // _APP_DELEGATE_H_ + diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h b/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h deleted file mode 100755 index cf42725b33..0000000000 --- a/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h -// ___PROJECTNAME___ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// - -#import -#import "cocos2d.h" - -@class RootViewController; - -@interface ___PROJECTNAMEASIDENTIFIER___AppDelegate : NSObject { - UIWindow *window; - RootViewController *viewController; - cocos2d::CCXEGLView *view; -} - -@property (nonatomic, retain) UIWindow *window; - -@end diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm b/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm deleted file mode 100755 index ec89c8241f..0000000000 --- a/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAMEASIDENTIFIER___AppDelegate.mm +++ /dev/null @@ -1,98 +0,0 @@ - // - // apptestAppDelegate.m - // apptest - // - // Created by Walzer on 11-1-17. - // Copyright __MyCompanyName__ 2011. All rights reserved. - // - -#import "EAGLView.h" -#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" -#import "HelloWorldScene.h" -#import "platform/iphone/CCDirectorCaller.h" - -@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate - -@synthesize window; - -- (void) applicationDidFinishLaunching:(UIApplication*)application -{ - window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; - EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] - pixelFormat: kEAGLColorFormatRGBA8 - depthFormat: 0 - preserveBackbuffer: NO - sharegroup:nil - multiSampling:NO - numberOfSamples:0]; - [__glView setMultipleTouchEnabled:YES]; - [window addSubview: __glView]; - [window makeKeyAndVisible]; - - [[UIApplication sharedApplication] setStatusBarHidden: YES]; - - // // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices - // if (! CCDirector::sharedDirector()->enableRetinaDisplay(true)) { - // CCLOG("Retina Display Not supported"); - // } - - // init director - view = new cocos2d::CCXEGLView(); - cocos2d::CCDirector *pDirector = cocos2d::CCDirector::sharedDirector(); - pDirector->setOpenGLView(view); - - cocos2d::CCDirector::sharedDirector()->setDeviceOrientation(cocos2d::kCCDeviceOrientationLandscapeLeft); - - // turn on display FPS - pDirector->setDisplayFPS(true); - - // create a scene. it's an autorelease object - cocos2d::CCScene *pScene = HelloWorld::scene(); - - // run - pDirector->runWithScene(pScene); - - // start mainloop - [[CCDirectorCaller sharedDirectorCaller] startMainLoop]; -} - - -- (void)applicationWillResignActive:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->resume(); -} - -- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->purgeCachedData(); -} - --(void) applicationDidEnterBackground:(UIApplication*)application { - cocos2d::CCDirector::sharedDirector()->stopAnimation(); -} - --(void) applicationWillEnterForeground:(UIApplication*)application { - cocos2d::CCDirector::sharedDirector()->startAnimation(); -} - -- (void)applicationWillTerminate:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->end(); - - [viewController release]; - - [window release]; -} - -- (void)applicationSignificantTimeChange:(UIApplication *)application { - cocos2d::CCDirector::sharedDirector()->setNextDeltaTimeZero(true); -} - -- (void)dealloc { - delete view; - [window release]; - [super dealloc]; -} - -@end diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id b/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id index 4c4cf83c7e..c69d030c09 100644 --- a/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/template/ios_mac/cocos2d-x_chipmunk_app/___PROJECTNAME___.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -31d059bae90b466d226532d68266be129882eb4d \ No newline at end of file +c61d7da24a3e6a4284e796e3ece68928ef2cca59 \ No newline at end of file diff --git a/template/ios_mac/cocos2d-x_chipmunk_app/main.m b/template/ios_mac/cocos2d-x_chipmunk_app/main.m index a42b040336..106d54c93e 100755 --- a/template/ios_mac/cocos2d-x_chipmunk_app/main.m +++ b/template/ios_mac/cocos2d-x_chipmunk_app/main.m @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppDelegate"); + int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppController"); [pool release]; return retVal; }