mirror of https://github.com/axmolengine/axmol.git
merge HelloLua modifications & updates into xcode4 template for lua.
This commit is contained in:
parent
cf7d411c71
commit
b0be69e26e
|
@ -1,8 +1,10 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
:m_pLuaEngine(NULL)
|
||||
|
@ -11,6 +13,8 @@ AppDelegate::AppDelegate()
|
|||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
// end simple audio engine here, or it may crashed on win32
|
||||
SimpleAudioEngine::sharedEngine()->end();
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
||||
CC_SAFE_DELETE(m_pLuaEngine);
|
||||
}
|
||||
|
@ -105,35 +109,9 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
}
|
||||
#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)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||
printf("%s", path.c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
require "hello2"
|
||||
|
||||
cocos2d.CCLuaLog("result is " .. myadd(3, 5))
|
||||
|
||||
-- create scene & layer
|
||||
layerFarm = cocos2d.CCLayer:node()
|
||||
layerFarm:setIsTouchEnabled(true)
|
||||
|
@ -31,6 +35,7 @@ function btnTouchMove(e)
|
|||
end
|
||||
|
||||
function btnTouchBegin(e)
|
||||
cocos2d.CCScheduler:sharedScheduler():unscheduleScriptFunc("tick")
|
||||
cocos2d.CCLuaLog("btnTouchBegin")
|
||||
for k,v in ipairs(e) do
|
||||
pointBegin = v:locationInView(v:view())
|
||||
|
@ -132,7 +137,7 @@ layerMenu:addChild(menuTools)
|
|||
|
||||
function tick()
|
||||
|
||||
point = spriteDog:getPosition();
|
||||
local point = spriteDog:getPosition();
|
||||
|
||||
if point.x > winSize.width then
|
||||
point.x = 0
|
||||
|
@ -144,10 +149,16 @@ function tick()
|
|||
|
||||
end
|
||||
|
||||
-- avoid memory leak
|
||||
collectgarbage( "setpause", 100)
|
||||
collectgarbage( "setstepmul", 5000)
|
||||
|
||||
|
||||
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false)
|
||||
|
||||
-- run
|
||||
-- play background music
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
||||
|
||||
-- preload effect
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");
|
||||
-- run
|
||||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
function myadd(x, y)
|
||||
return x + y
|
||||
end
|
Loading…
Reference in New Issue