From b563c52e10c98d5b2cfee800ca6927e2c4ddc4e5 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 16 Sep 2013 16:55:16 +0800 Subject: [PATCH] Issue:Resolve the carsh of the simple game test sample and modify the main.cpps in the template for the android projects --- .../Cpp/SimpleGame/Classes/HelloWorldScene.cpp | 18 ++++++++++++++++++ .../proj.android/jni/hellocpp/main.cpp | 2 +- .../proj.android/jni/hellojavascript/main.cpp | 2 +- .../proj.android/jni/hellolua/main.cpp | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/samples/Cpp/SimpleGame/Classes/HelloWorldScene.cpp b/samples/Cpp/SimpleGame/Classes/HelloWorldScene.cpp index 65ce917c6f..933c5c2ff2 100644 --- a/samples/Cpp/SimpleGame/Classes/HelloWorldScene.cpp +++ b/samples/Cpp/SimpleGame/Classes/HelloWorldScene.cpp @@ -103,7 +103,16 @@ bool HelloWorld::init() this->setTouchEnabled(true); _targets = new Array; + if (nullptr != _targets) + { + _targets->initWithCapacity(7); + } _projectiles = new Array; + if (nullptr != _projectiles) + { + _projectiles->initWithCapacity(7); + } + // use updateGame instead of update, otherwise it will conflit with SelectorProtocol::update // see http://www.cocos2d-x.org/boards/6/topics/1478 @@ -240,6 +249,11 @@ void HelloWorld::ccTouchesEnded(Set* touches, Event* event) void HelloWorld::updateGame(float dt) { Array *projectilesToDelete = new Array; + if (nullptr != projectilesToDelete) + { + projectilesToDelete->initWithCapacity(7); + } + Object* it = NULL; Object* jt = NULL; @@ -254,6 +268,10 @@ void HelloWorld::updateGame(float dt) projectile->getContentSize().height); auto targetsToDelete =new Array; + if (nullptr != targetsToDelete) + { + targetsToDelete->initWithCapacity(7); + } // for (jt = _targets->begin(); jt != _targets->end(); jt++) CCARRAY_FOREACH(_targets, jt) diff --git a/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp b/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp index ca56f8d7ff..a8b36b317d 100644 --- a/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp +++ b/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp @@ -10,7 +10,7 @@ using namespace cocos2d; -void cocos_android_app_init (void) { +void cocos_android_app_init (struct android_app* app) { LOGD("cocos_android_app_init"); AppDelegate *pAppDelegate = new AppDelegate(); } diff --git a/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp b/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp index 3d2a59ddfc..9793beefb1 100644 --- a/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp +++ b/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp @@ -10,7 +10,7 @@ using namespace cocos2d; -void cocos_android_app_init (void) { +void cocos_android_app_init (struct android_app* app) { LOGD("cocos_android_app_init"); AppDelegate *pAppDelegate = new AppDelegate(); } diff --git a/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp b/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp index ca56f8d7ff..a8b36b317d 100644 --- a/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp +++ b/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp @@ -10,7 +10,7 @@ using namespace cocos2d; -void cocos_android_app_init (void) { +void cocos_android_app_init (struct android_app* app) { LOGD("cocos_android_app_init"); AppDelegate *pAppDelegate = new AppDelegate(); }