Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from minggo/iss538
[iOS] fixed #538: add template of lua for xcode3
- Loading branch information
Showing
15 changed files
with
545 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+4 KB
template/xcode3/cocos2d-x_lua_app/Classes/.____PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
Binary file not shown.
Binary file added
BIN
+4 KB
template/xcode3/cocos2d-x_lua_app/Classes/.____PROJECTNAMEASIDENTIFIER___AppDelegate.h
Binary file not shown.
160 changes: 160 additions & 0 deletions
160
template/xcode3/cocos2d-x_lua_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#include "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" | ||
|
||
#include "cocos2d.h" | ||
|
||
USING_NS_CC; | ||
|
||
AppDelegate::AppDelegate() | ||
:m_pLuaEngine(NULL) | ||
{ | ||
} | ||
|
||
AppDelegate::~AppDelegate() | ||
{ | ||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine(); | ||
CC_SAFE_DELETE(m_pLuaEngine); | ||
} | ||
|
||
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"), 480, 320)); | ||
|
||
#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_ANDROID) | ||
|
||
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp | ||
// the default setting is to create a fullscreen view | ||
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp | ||
|
||
#endif // CC_PLATFORM_ANDROID | ||
|
||
#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, WM_WINDOW_ROTATE_MODE_CW)); | ||
|
||
#ifndef _TRANZDA_VM_ | ||
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file | ||
cocos2d::CCFileUtils::setResource("HelloWorld.zip"); | ||
#endif | ||
|
||
#endif // CC_PLATFORM_WOPHONE | ||
|
||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY) | ||
// MaxAksenov said it's NOT a very elegant solution. I agree, haha | ||
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); | ||
#endif | ||
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); | ||
|
||
// turn on display FPS | ||
pDirector->setDisplayFPS(true); | ||
|
||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); | ||
|
||
// set FPS. the default value is 1.0/60 if you don't call this | ||
pDirector->setAnimationInterval(1.0 / 60); | ||
|
||
// register lua engine | ||
m_pLuaEngine = new LuaEngine; | ||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine); | ||
|
||
#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; | ||
|
||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes); | ||
delete []pCodes; | ||
} | ||
#endif | ||
|
||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) | ||
// CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile("./../../HelloLua/Resource/hello.lua"); | ||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile("./../../HelloLua/Resource/hello.lua"); | ||
|
||
/* | ||
* Another way to run lua script. | ||
* Load the file into memory and run it. | ||
* | ||
unsigned long size; | ||
char *pFileContent = (char*)CCFileUtils::getFileData("./../../HelloLua/Resource/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 *pTmp = new char[size + 1]; | ||
pTmp[size] = '\0'; | ||
memcpy(pTmp, pFileContent, size); | ||
delete[] pFileContent; | ||
string code(pTmp); | ||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteScriptFile(code); | ||
delete []pTmp; | ||
} | ||
*/ | ||
|
||
#endif | ||
|
||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) | ||
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); | ||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua"); | ||
printf("%s", path.c_str()); | ||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str()); | ||
#endif | ||
|
||
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(); | ||
} |
47 changes: 47 additions & 0 deletions
47
template/xcode3/cocos2d-x_lua_app/Classes/___PROJECTNAMEASIDENTIFIER___AppDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef ___PROJECTNAMEASIDENTIFIER___AppDelegate_H__ | ||
#define ___PROJECTNAMEASIDENTIFIER___AppDelegate_H__ | ||
|
||
#include "CCApplication.h" | ||
#include "LuaEngine.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(); | ||
|
||
private: | ||
LuaEngine* m_pLuaEngine; | ||
}; | ||
|
||
#endif // ___PROJECTNAMEASIDENTIFIER___AppDelegate_H__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cocos2d-x http://www.cocos2d-x.org | ||
|
||
Copyright (c) 2008-2010 - (see each file to see the different copyright owners) | ||
|
||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
License for Lua 5.0 and later versions | ||
http://www.lua.org/license.html | ||
|
||
Copyright © 1994Ð2011 Lua.org, PUC-Rio. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
1 change: 1 addition & 0 deletions
1
template/xcode3/cocos2d-x_lua_app/Resource/90001.jpg.REMOVED.git-id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d7290c34702d1c6bdb368acb060d93b42d5deff8 |
Oops, something went wrong.