From 22b2f722b585d34f0315b15fdb5224a0c9c4c73f Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 4 May 2012 14:31:56 +0800 Subject: [PATCH 1/2] fixed #1220: Using CCString::stringWithContentsOfFile to get string from lua script files. --- HelloLua/Classes/AppDelegate.cpp | 47 ++++------------- HelloLua/proj.android/build_native.sh | 4 +- HelloLua/proj.android/default.properties | 2 - .../gen/org/cocos2dx/hellolua/R.java | 52 +++++++++---------- HelloLua/proj.android/jni/helloworld/main.cpp | 3 ++ HelloLua/proj.android/project.properties | 2 +- .../Templates/1033/Classes/AppDelegate.cpp | 19 ++----- .../Classes/AppDelegate.cpp | 39 +++----------- .../android/jni/LuaProjectTemplate/main.cpp | 3 ++ 9 files changed, 55 insertions(+), 116 deletions(-) delete mode 100644 HelloLua/proj.android/default.properties diff --git a/HelloLua/Classes/AppDelegate.cpp b/HelloLua/Classes/AppDelegate.cpp index d8deb045a5..3fa9228bd9 100644 --- a/HelloLua/Classes/AppDelegate.cpp +++ b/HelloLua/Classes/AppDelegate.cpp @@ -1,23 +1,9 @@ - #include "cocos2d.h" #include "AppDelegate.h" #include "SimpleAudioEngine.h" #include "CCScriptSupport.h" #include "CCLuaEngine.h" -#define IPAD 0 - -#if IPAD -#define CC_WIDTH 1024 -#define CC_HEIGHT 768 -#elif IPHONE_4 -#define CC_WIDTH 960 -#define CC_HEIGHT 640 -#else -#define CC_WIDTH 480 -#define CC_HEIGHT 320 -#endif - USING_NS_CC; using namespace CocosDenshion; @@ -55,24 +41,13 @@ bool AppDelegate::applicationDidFinishLaunching() CCScriptEngineProtocol* pEngine = CCLuaEngine::engine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - unsigned long size; - char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size); - - if (pFileContent) - { - // copy the file contents and add '\0' at the end, or the lua parser can not parse it - char *pCodes = new char[size + 1]; - pCodes[size] = '\0'; - memcpy(pCodes, pFileContent, size); - delete[] pFileContent; - - pEngine->executeString(pCodes); - delete []pCodes; - } -#endif - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + CCString* pstrFileContent = CCString::stringWithContentsOfFile("hello.lua"); + if (pstrFileContent) + { + pEngine->executeString(pstrFileContent->getCString()); + } +#else std::string path = CCFileUtils::fullPathFromRelativePath("hello.lua"); pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str()); pEngine->executeScriptFile(path.c_str()); @@ -85,16 +60,12 @@ bool AppDelegate::applicationDidFinishLaunching() void AppDelegate::applicationDidEnterBackground() { CCDirector::sharedDirector()->pause(); - - // if you use SimpleAudioEngine, it must be pause - // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); + 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(); + SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); } diff --git a/HelloLua/proj.android/build_native.sh b/HelloLua/proj.android/build_native.sh index 1915d06719..0b836bf1d3 100755 --- a/HelloLua/proj.android/build_native.sh +++ b/HelloLua/proj.android/build_native.sh @@ -1,6 +1,6 @@ # set params -NDK_ROOT_LOCAL=/cygdrive/d/programe/android/ndk/android-ndk-r7b -COCOS2DX_ROOT_LOCAL=/cygdrive/e/cocos2d-x +NDK_ROOT_LOCAL=/cygdrive/e/android/android-ndk-r8 +COCOS2DX_ROOT_LOCAL=/cygdrive/f/Project/dumganhar/cocos2d-x buildexternalsfromsource= diff --git a/HelloLua/proj.android/default.properties b/HelloLua/proj.android/default.properties deleted file mode 100644 index 51ff180e82..0000000000 --- a/HelloLua/proj.android/default.properties +++ /dev/null @@ -1,2 +0,0 @@ -# Project target. -target=android-10 diff --git a/HelloLua/proj.android/gen/org/cocos2dx/hellolua/R.java b/HelloLua/proj.android/gen/org/cocos2dx/hellolua/R.java index bad0413877..ba4eac96cd 100644 --- a/HelloLua/proj.android/gen/org/cocos2dx/hellolua/R.java +++ b/HelloLua/proj.android/gen/org/cocos2dx/hellolua/R.java @@ -1,26 +1,26 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package org.cocos2dx.hellolua; - -public final class R { - public static final class attr { - } - public static final class drawable { - public static final int icon=0x7f020000; - } - public static final class id { - public static final int test_demo_gl_surfaceview=0x7f050001; - public static final int textField=0x7f050000; - } - public static final class layout { - public static final int game_demo=0x7f030000; - } - public static final class string { - public static final int app_name=0x7f040000; - } -} +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package org.cocos2dx.hellolua; + +public final class R { + public static final class attr { + } + public static final class drawable { + public static final int icon=0x7f020000; + } + public static final class id { + public static final int test_demo_gl_surfaceview=0x7f050001; + public static final int textField=0x7f050000; + } + public static final class layout { + public static final int game_demo=0x7f030000; + } + public static final class string { + public static final int app_name=0x7f040000; + } +} diff --git a/HelloLua/proj.android/jni/helloworld/main.cpp b/HelloLua/proj.android/jni/helloworld/main.cpp index ceb2aa7b72..39957ab36c 100644 --- a/HelloLua/proj.android/jni/helloworld/main.cpp +++ b/HelloLua/proj.android/jni/helloworld/main.cpp @@ -34,6 +34,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { + ccDrawInit(); + ccGLInvalidateStateCache(); + CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); CCTextureCache::reloadAllTextures(); CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); diff --git a/HelloLua/proj.android/project.properties b/HelloLua/proj.android/project.properties index ea89160e01..f049142c17 100644 --- a/HelloLua/proj.android/project.properties +++ b/HelloLua/proj.android/project.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-8 +target=android-10 diff --git a/template/msvc/CCAppWiz.win32/Templates/1033/Classes/AppDelegate.cpp b/template/msvc/CCAppWiz.win32/Templates/1033/Classes/AppDelegate.cpp index 4cbceca0cc..3c29270c50 100644 --- a/template/msvc/CCAppWiz.win32/Templates/1033/Classes/AppDelegate.cpp +++ b/template/msvc/CCAppWiz.win32/Templates/1033/Classes/AppDelegate.cpp @@ -46,23 +46,12 @@ bool AppDelegate::applicationDidFinishLaunching() CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - unsigned long size; - char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size); - - if (pFileContent) + CCString* pstrFileContent = CCString::stringWithContentsOfFile("hello.lua"); + if (pstrFileContent) { - // copy the file contents and add '\0' at the end, or the lua parser can not parse it - char *pCodes = new char[size + 1]; - pCodes[size] = '\0'; - memcpy(pCodes, pFileContent, size); - delete[] pFileContent; - - pEngine->executeString(pCodes); - delete []pCodes; + pEngine->executeString(pstrFileContent->getCString()); } -#endif - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) +#else std::string path = CCFileUtils::fullPathFromRelativePath("hello.lua"); pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str()); pEngine->executeScriptFile(path.c_str()); diff --git a/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp b/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp index e353113b47..7649a5ff8e 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp +++ b/template/xcode4/cocos2dx_lua.xctemplate/Classes/AppDelegate.cpp @@ -1,23 +1,9 @@ - #include "cocos2d.h" #include "AppDelegate.h" #include "SimpleAudioEngine.h" #include "CCScriptSupport.h" #include "CCLuaEngine.h" -#define IPAD 0 - -#if IPAD -#define CC_WIDTH 1024 -#define CC_HEIGHT 768 -#elif IPHONE_4 -#define CC_WIDTH 960 -#define CC_HEIGHT 640 -#else -#define CC_WIDTH 480 -#define CC_HEIGHT 320 -#endif - USING_NS_CC; using namespace std; using namespace CocosDenshion; @@ -56,24 +42,13 @@ bool AppDelegate::applicationDidFinishLaunching() CCScriptEngineProtocol* pEngine = CCLuaEngine::engine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - unsigned long size; - char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size); - - if (pFileContent) - { - // copy the file contents and add '\0' at the end, or the lua parser can not parse it - char *pCodes = new char[size + 1]; - pCodes[size] = '\0'; - memcpy(pCodes, pFileContent, size); - delete[] pFileContent; - - pEngine->executeString(pCodes); - delete []pCodes; - } -#endif - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + CCString* pstrFileContent = CCString::stringWithContentsOfFile("hello.lua"); + if (pstrFileContent) + { + pEngine->executeString(pstrFileContent->getCString()); + } +#else string path = CCFileUtils::fullPathFromRelativePath("hello.lua"); pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str()); pEngine->executeScriptFile(path.c_str()); diff --git a/tools/lua_project_generator/template/android/jni/LuaProjectTemplate/main.cpp b/tools/lua_project_generator/template/android/jni/LuaProjectTemplate/main.cpp index cc1c086a5c..e1d0daff5f 100644 --- a/tools/lua_project_generator/template/android/jni/LuaProjectTemplate/main.cpp +++ b/tools/lua_project_generator/template/android/jni/LuaProjectTemplate/main.cpp @@ -26,6 +26,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { + ccDrawInit(); + ccGLInvalidateStateCache(); + CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); CCTextureCache::reloadAllTextures(); CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); From 14b923409a04c8888a7eefae04bda244e4871f56 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 4 May 2012 16:22:50 +0800 Subject: [PATCH 2/2] fixed #1217: implement reverse() for all subclass of CCEaseAction that missing it --- cocos2dx/actions/CCActionEase.cpp | 51 +++-- cocos2dx/actions/CCActionEase.h | 7 + cocos2dx/actions/CCActionInterval.cpp | 21 +- .../tests/ActionsEaseTest/ActionsEaseTest.cpp | 185 +++++++++++------- 4 files changed, 171 insertions(+), 93 deletions(-) diff --git a/cocos2dx/actions/CCActionEase.cpp b/cocos2dx/actions/CCActionEase.cpp index 07a2639f30..4f4bf7a7c7 100644 --- a/cocos2dx/actions/CCActionEase.cpp +++ b/cocos2dx/actions/CCActionEase.cpp @@ -234,6 +234,11 @@ void CCEaseIn::update(ccTime time) m_pOther->update(powf(time, m_fRate)); } +CCActionInterval* CCEaseIn::reverse(void) +{ + return CCEaseIn::actionWithAction(m_pOther->reverse(), 1 / m_fRate); +} + // // EaseOut // @@ -281,6 +286,11 @@ void CCEaseOut::update(ccTime time) m_pOther->update(powf(time, 1 / m_fRate)); } +CCActionInterval* CCEaseOut::reverse() +{ + return CCEaseOut::actionWithAction(m_pOther->reverse(), 1 / m_fRate); +} + // // EaseInOut // @@ -325,14 +335,6 @@ CCObject* CCEaseInOut::copyWithZone(CCZone *pZone) void CCEaseInOut::update(ccTime time) { - int sign = 1; - int r = (int) m_fRate; - - if (r % 2 == 0) - { - sign = -1; - } - time *= 2; if (time < 1) { @@ -340,7 +342,7 @@ void CCEaseInOut::update(ccTime time) } else { - m_pOther->update(sign * 0.5f * (powf(time - 2, m_fRate) + sign * 2)); + m_pOther->update(1.0f - 0.5f * powf(2-time, m_fRate)); } } @@ -505,12 +507,17 @@ void CCEaseExponentialInOut::update(ccTime time) } else { - time = 0.5f * (-powf(2, 10 * (time - 1)) + 2); + time = 0.5f * (-powf(2, -10 * (time - 1)) + 2); } m_pOther->update(time); } +CCActionInterval* CCEaseExponentialInOut::reverse() +{ + return CCEaseExponentialInOut::actionWithAction(m_pOther->reverse()); +} + // // EaseSineIn // @@ -662,6 +669,11 @@ void CCEaseSineInOut::update(ccTime time) m_pOther->update(-0.5f * (cosf((float)M_PI * time) - 1)); } +CCActionInterval* CCEaseSineInOut::reverse() +{ + return CCEaseSineInOut::actionWithAction(m_pOther->reverse()); +} + // // EaseElastic // @@ -740,7 +752,7 @@ CCObject* CCEaseElastic::copyWithZone(CCZone *pZone) CCActionInterval* CCEaseElastic::reverse(void) { - CCAssert(0, ""); + CCAssert(0, "Override me"); return NULL; } @@ -1002,7 +1014,7 @@ void CCEaseElasticInOut::update(ccTime time) CCActionInterval* CCEaseElasticInOut::reverse(void) { - return CCEaseInOut::actionWithAction(m_pOther->reverse(), m_fPeriod); + return CCEaseElasticInOut::actionWithAction(m_pOther->reverse(), m_fPeriod); } // @@ -1068,6 +1080,11 @@ ccTime CCEaseBounce::bounceTime(ccTime time) return 7.5625f * time * time + 0.984375f; } +CCActionInterval* CCEaseBounce::reverse() +{ + return CCEaseBounce::actionWithAction(m_pOther->reverse()); +} + // // EaseBounceIn // @@ -1232,6 +1249,11 @@ void CCEaseBounceInOut::update(ccTime time) m_pOther->update(newT); } +CCActionInterval* CCEaseBounceInOut::reverse() +{ + return CCEaseBounceInOut::actionWithAction(m_pOther->reverse()); +} + // // EaseBackIn // @@ -1398,4 +1420,9 @@ void CCEaseBackInOut::update(ccTime time) } } +CCActionInterval* CCEaseBackInOut::reverse() +{ + return CCEaseBackInOut::actionWithAction(m_pOther->reverse()); +} + NS_CC_END diff --git a/cocos2dx/actions/CCActionEase.h b/cocos2dx/actions/CCActionEase.h index 34e11d69da..ea2ab39621 100644 --- a/cocos2dx/actions/CCActionEase.h +++ b/cocos2dx/actions/CCActionEase.h @@ -92,6 +92,7 @@ class CC_DLL CCEaseIn : public CCEaseRateAction { public: virtual void update(ccTime time); + virtual CCActionInterval* reverse(void); virtual CCObject* copyWithZone(CCZone* pZone); public: /** Creates the action with the inner action and the rate parameter */ @@ -105,6 +106,7 @@ class CC_DLL CCEaseOut : public CCEaseRateAction { public: virtual void update(ccTime time); + virtual CCActionInterval* reverse(); virtual CCObject* copyWithZone(CCZone* pZone); public: @@ -166,6 +168,7 @@ class CC_DLL CCEaseExponentialInOut : public CCActionEase public: virtual void update(ccTime time); virtual CCObject* copyWithZone(CCZone* pZone); + virtual CCActionInterval* reverse(); public: /** creates the action */ @@ -211,6 +214,7 @@ class CC_DLL CCEaseSineInOut : public CCActionEase public: virtual void update(ccTime time); virtual CCObject* copyWithZone(CCZone* pZone); + virtual CCActionInterval* reverse(); public: /** creates the action */ @@ -313,6 +317,7 @@ class CC_DLL CCEaseBounce : public CCActionEase public: ccTime bounceTime(ccTime time); virtual CCObject* copyWithZone(CCZone* pZone); + virtual CCActionInterval* reverse(); public: /** creates the action */ @@ -363,6 +368,7 @@ class CC_DLL CCEaseBounceInOut : public CCEaseBounce public: virtual void update(ccTime time); virtual CCObject* copyWithZone(CCZone* pZone); + virtual CCActionInterval* reverse(); public: /** creates the action */ @@ -413,6 +419,7 @@ class CC_DLL CCEaseBackInOut : public CCActionEase public: virtual void update(ccTime time); virtual CCObject* copyWithZone(CCZone* pZone); + virtual CCActionInterval* reverse(); public: /** creates the action */ diff --git a/cocos2dx/actions/CCActionInterval.cpp b/cocos2dx/actions/CCActionInterval.cpp index 4d4ab7f721..6c6861eda9 100644 --- a/cocos2dx/actions/CCActionInterval.cpp +++ b/cocos2dx/actions/CCActionInterval.cpp @@ -76,9 +76,6 @@ CCObject* CCActionInterval::copyWithZone(CCZone *pZone) } else { - // action's base class , must be called using __super::copyWithZone(), after overriding from derived class - CCAssert(0, ""); - pCopy = new CCActionInterval(); pZone = pNewZone = new CCZone(pCopy); } @@ -109,9 +106,13 @@ void CCActionInterval::step(ccTime dt) { m_elapsed += dt; } - -// update(min(1, m_elapsed/m_fDuration)); - update(1 > m_elapsed/m_fDuration ? m_elapsed/m_fDuration : 1); + + this->update(MAX (0, // needed for rewind. elapsed could be negative + MIN(1, m_elapsed / + MAX(m_fDuration, FLT_EPSILON) // division by 0 + ) + ) + ); } void CCActionInterval::setAmplitudeRate(CCFloat amp) @@ -138,13 +139,7 @@ void CCActionInterval::startWithTarget(CCNode *pTarget) CCActionInterval* CCActionInterval::reverse(void) { - /* - NSException* myException = [NSException - exceptionWithName:@"ReverseActionNotImplemented" - reason:@"Reverse Action not implemented" - userInfo:nil]; - @throw myException; - */ + CCAssert(false, "CCIntervalAction: reverse not implemented."); return NULL; } diff --git a/tests/tests/ActionsEaseTest/ActionsEaseTest.cpp b/tests/tests/ActionsEaseTest/ActionsEaseTest.cpp index 56e8c65cf5..cb4aa3b83c 100644 --- a/tests/tests/ActionsEaseTest/ActionsEaseTest.cpp +++ b/tests/tests/ActionsEaseTest/ActionsEaseTest.cpp @@ -16,36 +16,39 @@ CCLayer* restartEaseAction(); // SpriteEase // //------------------------------------------------------------------ - +#define CCCA(x) (x->copy()->autorelease()) void SpriteEase::onEnter() { EaseSpriteDemo::onEnter(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0) ); + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130,0)); CCActionInterval* move_back = move->reverse(); - CCActionInterval* move_ease_in = (CCActionInterval*)CCEaseIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 2.5f); + CCActionInterval* move_ease_in = CCEaseIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 2.5f); CCActionInterval* move_ease_in_back = move_ease_in->reverse(); CCActionInterval* move_ease_out = CCEaseOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 2.5f); CCActionInterval* move_ease_out_back = move_ease_out->reverse(); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); - CCFiniteTimeAction* seq1 = CCSequence::actions(move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, move_ease_in_back, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, move_ease_out_back, NULL); + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); - CCAction *a2 = m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1) ); + CCAction *a2 = m_grossini->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); a2->setTag(1); - CCAction *a1 = m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2) ); + CCAction *a1 = m_tamara->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); a1->setTag(1); - CCAction *a = m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3) ); + CCAction *a = m_kathia->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq3)); a->setTag(1); - schedule(schedule_selector(SpriteEase::testStopAction), 6); + schedule(schedule_selector(SpriteEase::testStopAction), 6.25f); } void SpriteEase::testStopAction(ccTime dt) @@ -71,8 +74,10 @@ std::string SpriteEase::title() void SpriteEaseInOut::onEnter() { EaseSpriteDemo::onEnter(); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130,0)); // id move_back = move->reverse(); CCActionInterval* move_ease_inout1 = CCEaseInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 0.65f); @@ -83,15 +88,16 @@ void SpriteEaseInOut::onEnter() CCActionInterval* move_ease_inout3 = CCEaseInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 1.0f); CCActionInterval* move_ease_inout_back3 = move_ease_inout3->reverse(); - - CCFiniteTimeAction* seq1 = CCSequence::actions( move_ease_inout1, move_ease_inout_back1, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_inout2, move_ease_inout_back2, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_inout3, move_ease_inout_back3, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions( move_ease_inout1, delay, move_ease_inout_back1, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_inout2, CCCA(delay), move_ease_inout_back2, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_inout3, CCCA(delay), move_ease_inout_back3, CCCA(delay), NULL); - m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1) ); - m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2) ); - m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3) ); + m_tamara->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); + m_kathia->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); + m_grossini->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq3)); } @@ -109,8 +115,10 @@ std::string SpriteEaseInOut::title() void SpriteEaseExponential::onEnter() { EaseSpriteDemo::onEnter(); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130,0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease_in = CCEaseExponentialIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); @@ -119,15 +127,16 @@ void SpriteEaseExponential::onEnter() CCActionInterval* move_ease_out = CCEaseExponentialOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_out_back = move_ease_out->reverse(); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_in, move_ease_in_back, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_out, move_ease_out_back, NULL); + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); - m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1) ); - m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2) ); - m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3) ); + m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); + m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); + m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3)); } @@ -144,15 +153,19 @@ std::string SpriteEaseExponential::title() void SpriteEaseExponentialInOut::onEnter() { EaseSpriteDemo::onEnter(); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease = CCEaseExponentialInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_back = move_ease->reverse(); //--> reverse() - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease, move_ease_back, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions( move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease, delay, move_ease_back, CCCA(delay), NULL); this->positionForTwo(); @@ -175,8 +188,10 @@ std::string SpriteEaseExponentialInOut::title() void SpriteEaseSine::onEnter() { EaseSpriteDemo::onEnter(); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease_in = CCEaseSineIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); @@ -185,10 +200,11 @@ void SpriteEaseSine::onEnter() CCActionInterval* move_ease_out = CCEaseSineOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_out_back = move_ease_out->reverse(); - - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_in, move_ease_in_back, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_out, move_ease_out_back, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); @@ -211,15 +227,19 @@ std::string SpriteEaseSine::title() void SpriteEaseSineInOut::onEnter() { EaseSpriteDemo::onEnter(); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130,0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease = CCEaseSineInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_back = move_ease->reverse(); - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease, move_ease_back, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease, CCCA(delay), move_ease_back, CCCA(delay), NULL); this->positionForTwo(); @@ -241,7 +261,10 @@ std::string SpriteEaseSineInOut::title() void SpriteEaseElastic::onEnter() { EaseSpriteDemo::onEnter(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease_in = CCEaseElasticIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); @@ -249,10 +272,12 @@ void SpriteEaseElastic::onEnter() CCActionInterval* move_ease_out = CCEaseElasticOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_out_back = move_ease_out->reverse(); + + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_in, move_ease_in_back, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_out, move_ease_out_back, NULL); + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); @@ -275,7 +300,9 @@ void SpriteEaseElasticInOut::onEnter() { EaseSpriteDemo::onEnter(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_ease_inout1 = CCEaseElasticInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 0.3f); CCActionInterval* move_ease_inout_back1 = move_ease_inout1->reverse(); @@ -286,10 +313,11 @@ void SpriteEaseElasticInOut::onEnter() CCActionInterval* move_ease_inout3 = CCEaseElasticInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 0.6f); CCActionInterval* move_ease_inout_back3 = move_ease_inout3->reverse(); - - CCFiniteTimeAction* seq1 = CCSequence::actions( move_ease_inout1, move_ease_inout_back1, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_inout2, move_ease_inout_back2, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_inout3, move_ease_inout_back3, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions(move_ease_inout1, delay, move_ease_inout_back1, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_inout2, CCCA(delay), move_ease_inout_back2, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_inout3, CCCA(delay), move_ease_inout_back3, CCCA(delay), NULL); m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); @@ -312,7 +340,10 @@ std::string SpriteEaseElasticInOut::title() void SpriteEaseBounce::onEnter() { EaseSpriteDemo::onEnter(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease_in = CCEaseBounceIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); @@ -321,9 +352,11 @@ void SpriteEaseBounce::onEnter() CCActionInterval* move_ease_out = CCEaseBounceOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_out_back = move_ease_out->reverse(); - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_in, move_ease_in_back, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_out, move_ease_out_back, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); @@ -346,15 +379,19 @@ std::string SpriteEaseBounce::title() void SpriteEaseBounceInOut::onEnter() { EaseSpriteDemo::onEnter(); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease = CCEaseBounceInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_back = move_ease->reverse(); - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease, move_ease_back, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease, CCCA(delay), move_ease_back, CCCA(delay), NULL); this->positionForTwo(); @@ -377,22 +414,27 @@ std::string SpriteEaseBounceInOut::title() void SpriteEaseBack::onEnter() { EaseSpriteDemo::onEnter(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_back = move->reverse(); - CCActionInterval* move_ease_in = CCEaseBackIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); + CCActionInterval* move_ease_in = CCEaseBackIn::actionWithAction((CCActionInterval*)(move->copy()->autorelease())); CCActionInterval* move_ease_in_back = move_ease_in->reverse(); - CCActionInterval* move_ease_out = CCEaseBackOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); + CCActionInterval* move_ease_out = CCEaseBackOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease())); CCActionInterval* move_ease_out_back = move_ease_out->reverse(); - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease_in, move_ease_in_back, NULL); - CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_out, move_ease_out_back, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); - m_grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); - m_tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); - m_kathia->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3)); + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease_in, CCCA(delay), move_ease_in_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq3 = CCSequence::actions(move_ease_out, CCCA(delay), move_ease_out_back, CCCA(delay), NULL); + + m_grossini->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq1)); + m_tamara->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq2)); + m_kathia->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq3)); } @@ -410,14 +452,19 @@ std::string SpriteEaseBack::title() void SpriteEaseBackInOut::onEnter() { EaseSpriteDemo::onEnter(); - CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0)); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(s.width-130, 0)); CCActionInterval* move_back = move->reverse(); CCActionInterval* move_ease = CCEaseBackInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()) ); CCActionInterval* move_ease_back = move_ease->reverse(); - CCFiniteTimeAction* seq1 = CCSequence::actions( move, move_back, NULL); - CCFiniteTimeAction* seq2 = CCSequence::actions( move_ease, move_ease_back, NULL); + CCDelayTime *delay = CCDelayTime::actionWithDuration(0.25f); + + CCFiniteTimeAction* seq1 = CCSequence::actions(move, delay, move_back, CCCA(delay), NULL); + CCFiniteTimeAction* seq2 = CCSequence::actions(move_ease, CCCA(delay), move_ease_back, CCCA(delay), NULL); this->positionForTwo(); @@ -440,9 +487,11 @@ std::string SpriteEaseBackInOut::title() void SpeedTest::onEnter() { EaseSpriteDemo::onEnter(); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); // rotate and jump - CCActionInterval *jump1 = CCJumpBy::actionWithDuration(4, CCPointMake(-400,0), 100, 4); + CCActionInterval *jump1 = CCJumpBy::actionWithDuration(4, CCPointMake(-s.width+80, 0), 100, 4); CCActionInterval *jump2 = jump1->reverse(); CCActionInterval *rot1 = CCRotateBy::actionWithDuration(4, 360*2); CCActionInterval *rot2 = rot1->reverse(); @@ -459,9 +508,9 @@ void SpeedTest::onEnter() action2->setTag(kTagAction1); action3->setTag(kTagAction1); - m_grossini->runAction( action2 ); - m_tamara->runAction( action3 ); - m_kathia->runAction( action ); + m_grossini->runAction(action2); + m_tamara->runAction(action3); + m_kathia->runAction(action); this->schedule(schedule_selector(SpeedTest::altertime), 1.0f);//:@selector(altertime:) interval:1.0f]; }