mirror of https://github.com/axmolengine/axmol.git
Add Lua support for the win32 new project template.
This commit is contained in:
parent
739d6d30e5
commit
6649987955
|
@ -33,6 +33,7 @@
|
|||
<SYMBOL NAME='CC_USE_BOX2D' TYPE="checkbox" VALUE="true"></SYMBOL>
|
||||
<SYMBOL NAME='CC_USE_CHIPMUNK' TYPE="checkbox" VALUE="false"></SYMBOL>
|
||||
<SYMBOL NAME='CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE' TYPE="checkbox" VALUE="true"></SYMBOL>
|
||||
<SYMBOL NAME='CC_USE_LUA' TYPE="checkbox" VALUE="false"></SYMBOL>
|
||||
<SYMBOL NAME='CC_HAS_MAIN_FORM' TYPE="checkbox" VALUE="true"></SYMBOL>
|
||||
|
||||
<!-- Page 3 Controls -->
|
||||
|
@ -208,6 +209,12 @@
|
|||
<LABEL FOR="CC_AUDIO_ENGINE_SUMMARY"></LABEL>
|
||||
</SPAN>
|
||||
</LI>
|
||||
|
||||
<LI CLASS="LIST">
|
||||
<SPAN CLASS="SideBtnHidden" ID="CC_LUA_SUMMARY" TITLE="">
|
||||
<LABEL FOR="CC_LUA_SUMMARY"></LABEL>
|
||||
</SPAN>
|
||||
</LI>
|
||||
|
||||
</UL>
|
||||
|
||||
|
@ -365,6 +372,15 @@ function OnInit()
|
|||
{
|
||||
CC_AUDIO_ENGINE_SUMMARY.innerText = "None Audio Engine";
|
||||
}
|
||||
|
||||
if (window.external.FindSymbol("CC_USE_LUA"))
|
||||
{
|
||||
CC_LUA_SUMMARY.innerText = "Lua Supportted: Yes";
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_LUA_SUMMARY.innerText = "Lua Supportted: NO";
|
||||
}
|
||||
}
|
||||
|
||||
</SCRIPT>
|
||||
|
|
|
@ -212,7 +212,7 @@
|
|||
<TD VALIGN="top" WIDTH="12">
|
||||
|
||||
</TD>
|
||||
<TD VALIGN="top" HEIGHT="100%" COLSPAN="7">
|
||||
<TD VALIGN="top" COLSPAN="7">
|
||||
<SPAN CLASS="itemText">Select audio engine:
|
||||
<br />
|
||||
<br />
|
||||
|
@ -224,6 +224,26 @@
|
|||
<U>S</U>imple Audio Engine in Cocos Denshion</LABEL>
|
||||
</DIV>
|
||||
</SPAN>
|
||||
|
||||
<P CLASS="ElementSpacer"> </P>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="top" WIDTH="12">
|
||||
|
||||
</TD>
|
||||
<TD VALIGN="top" HEIGHT="100%" COLSPAN="7">
|
||||
<SPAN CLASS="itemText">Select Lua support:
|
||||
<br />
|
||||
<br />
|
||||
<INPUT CLASS="CheckBoxA" TYPE="checkbox" ID="CC_USE_LUA" ACCESSKEY="S" TITLE="Application uses liblua." value="ON" NAME="CC_USE_LUA onClick="OnUseLua();">
|
||||
<DIV CLASS="itemTextCheckboxB" ID="CC_USE_LUA_DIV" TITLE="Application uses liblua.">
|
||||
<LABEL FOR="CC_USE_LUA"
|
||||
TITLE="Application uses liblua. Include "LuaEngine.h" if needs."
|
||||
ID="CC_USE_LUA_LABEL">
|
||||
<U>S</U>upport Lua</LABEL>
|
||||
</DIV>
|
||||
</SPAN>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
|
@ -341,6 +361,7 @@ function OnInit()
|
|||
CC_USE_BOX2D.disabled = false;
|
||||
CC_USE_CHIPMUNK.disabled = false;
|
||||
CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE.disabled = false;
|
||||
CC_USE_LUA.disabled = false;
|
||||
|
||||
if (window.external.FindSymbol("CC_USE_BOX2D"))
|
||||
{
|
||||
|
@ -356,6 +377,11 @@ function OnInit()
|
|||
{
|
||||
CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE.checked = true;
|
||||
}
|
||||
|
||||
if (window.external.FindSymbol("CC_USE_LUA"))
|
||||
{
|
||||
CC_USE_LUA.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
function OnUseBox2D()
|
||||
|
@ -394,6 +420,19 @@ function OnUseCocosDenshionSimpleAudioEngine()
|
|||
}
|
||||
}
|
||||
|
||||
function OnUseLua()
|
||||
{
|
||||
if (CC_USE_LUA.checked)
|
||||
{
|
||||
window.external.AddSymbol("CC_USE_LUA", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.external.AddSymbol("CC_USE_LUA", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</SCRIPT>
|
||||
<SCRIPT ID="INCLUDE_SCRIPT" LANGUAGE="JSCRIPT"></SCRIPT>
|
||||
<SCRIPT ID="INCLUDE_COMMON" LANGUAGE="JSCRIPT"></SCRIPT>
|
||||
|
|
|
@ -231,6 +231,11 @@ function AddConfigurations(proj, strProjectName) {
|
|||
if (wizard.FindSymbol('CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) {
|
||||
strAddIncludeDir += ';..\\CocosDenshion\\Include';
|
||||
}
|
||||
if (wizard.FindSymbol('CC_USE_LUA')) {
|
||||
strAddIncludeDir += ';..\\lua\\cocos2dx_support';
|
||||
strAddIncludeDir += ';..\\lua\\tolua';
|
||||
strAddIncludeDir += ';..\\lua\\src';
|
||||
}
|
||||
CLTool.AdditionalIncludeDirectories = strAddIncludeDir;
|
||||
|
||||
CLTool.UsePrecompiledHeader = pchNone; // pchUseUsingSpecific;
|
||||
|
@ -282,6 +287,9 @@ function AddConfigurations(proj, strProjectName) {
|
|||
if (wizard.FindSymbol('CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) {
|
||||
strAddDepends += ' libCocosDenshion.lib';
|
||||
}
|
||||
if (wizard.FindSymbol('CC_USE_LUA')) {
|
||||
strAddDepends += ' liblua.lib';
|
||||
}
|
||||
LinkTool.AdditionalLibraryDirectories = '$(OutDir)';
|
||||
LinkTool.AdditionalDependencies = strAddDepends;
|
||||
|
||||
|
|
|
@ -6,11 +6,17 @@
|
|||
using namespace CocosDenshion;
|
||||
|
||||
[! endif]
|
||||
[! if !CC_USE_LUA]
|
||||
|
||||
#include "HelloWorldScene.h"
|
||||
[! endif]
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
[! if CC_USE_LUA]
|
||||
:m_pLuaEngine(NULL)
|
||||
[! endif]
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -20,6 +26,11 @@ AppDelegate::~AppDelegate()
|
|||
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
||||
SimpleAudioEngine::end();
|
||||
[! endif]
|
||||
[! if CC_USE_LUA]
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
||||
CC_SAFE_DELETE(m_pLuaEngine);
|
||||
[! endif]
|
||||
}
|
||||
|
||||
bool AppDelegate::initInstance()
|
||||
|
@ -83,12 +94,66 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
[! if CC_USE_LUA]
|
||||
// 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)
|
||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||
printf("%s", path.c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
[! else]
|
||||
// create a scene. it's an autorelease object
|
||||
CCScene *pScene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
pDirector->runWithScene(pScene);
|
||||
|
||||
[! endif]
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#define __APP_DELEGATE_H__
|
||||
|
||||
#include "CCApplication.h"
|
||||
[! if CC_USE_LUA]
|
||||
#include "LuaEngine.h"
|
||||
[! endif]
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
@ -37,6 +40,11 @@ public:
|
|||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
[! if CC_USE_LUA]
|
||||
|
||||
private:
|
||||
LuaEngine* m_pLuaEngine;
|
||||
[! endif]
|
||||
};
|
||||
|
||||
#endif // __APP_DELEGATE_H__
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
d7290c34702d1c6bdb368acb060d93b42d5deff8
|
|
@ -0,0 +1,146 @@
|
|||
-- create scene & layer
|
||||
layerFarm = cocos2d.CCLayer:node()
|
||||
layerFarm:setIsTouchEnabled(true)
|
||||
|
||||
layerMenu = cocos2d.CCLayer:node()
|
||||
|
||||
sceneGame = cocos2d.CCScene:node()
|
||||
sceneGame:addChild(layerFarm)
|
||||
sceneGame:addChild(layerMenu)
|
||||
|
||||
winSize = cocos2d.CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
-- add in farm background
|
||||
spriteFarm = cocos2d.CCSprite:spriteWithFile("farm.jpg")
|
||||
spriteFarm:setPosition(cocos2d.CCPoint(winSize.width/2 + 80, winSize.height/2))
|
||||
layerFarm:addChild(spriteFarm)
|
||||
|
||||
-- touch handers
|
||||
pointBegin = nil
|
||||
|
||||
function btnTouchMove(e)
|
||||
cocos2d.CCLuaLog("btnTouchMove")
|
||||
if pointBegin ~= nil then
|
||||
local v = e[1]
|
||||
local pointMove = v:locationInView(v:view())
|
||||
pointMove = cocos2d.CCDirector:sharedDirector():convertToGL(pointMove)
|
||||
local positionCurrent = layerFarm.__CCNode__:getPosition()
|
||||
layerFarm.__CCNode__:setPosition(cocos2d.CCPoint(positionCurrent.x + pointMove.x - pointBegin.x, positionCurrent.y + pointMove.y - pointBegin.y))
|
||||
pointBegin = pointMove
|
||||
end
|
||||
end
|
||||
|
||||
function btnTouchBegin(e)
|
||||
for k,v in ipairs(e) do
|
||||
pointBegin = v:locationInView(v:view())
|
||||
pointBegin = cocos2d.CCDirector:sharedDirector():convertToGL(pointBegin)
|
||||
cocos2d.CCLuaLog("btnTouchBegin, x= %d, y = %d", pointBegin.x, pointBegin.y)
|
||||
end
|
||||
end
|
||||
|
||||
function btnTouchEnd(e)
|
||||
cocos2d.CCLuaLog("btnTouchEnd")
|
||||
touchStart = nil
|
||||
end
|
||||
|
||||
-- regiester touch handlers
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHBEGAN, "btnTouchBegin")
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHMOVED, "btnTouchMove")
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHENDED, "btnTouchEnd")
|
||||
|
||||
|
||||
-- add land sprite
|
||||
for i=0,3,1 do
|
||||
for j=0,1,1 do
|
||||
spriteLand = cocos2d.CCSprite:spriteWithFile("land.png")
|
||||
layerFarm:addChild(spriteLand)
|
||||
spriteLand:setPosition(cocos2d.CCPoint(200+j*180 - i%2*90, 10+i*95/2))
|
||||
end
|
||||
end
|
||||
|
||||
-- add crop
|
||||
|
||||
for i=0,3,1 do
|
||||
for j=0,1,1 do
|
||||
|
||||
textureCrop = cocos2d.CCTextureCache:sharedTextureCache():addImage("crop.png")
|
||||
frameCrop = cocos2d.CCSpriteFrame:frameWithTexture(textureCrop, cocos2d.CCRectMake(0, 0, 105, 95))
|
||||
spriteCrop = cocos2d.CCSprite:spriteWithSpriteFrame(frameCrop);
|
||||
|
||||
layerFarm:addChild(spriteCrop)
|
||||
|
||||
spriteCrop:setPosition(cocos2d.CCPoint(10+200+j*180 - i%2*90, 30+10+i*95/2))
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- add the moving dog
|
||||
|
||||
FrameWidth = 105
|
||||
FrameHeight = 95
|
||||
|
||||
textureDog = cocos2d.CCTextureCache:sharedTextureCache():addImage("dog.png")
|
||||
frame0 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(0, 0, FrameWidth, FrameHeight))
|
||||
frame1 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(FrameWidth*1, 0, FrameWidth, FrameHeight))
|
||||
|
||||
spriteDog = cocos2d.CCSprite:spriteWithSpriteFrame(frame0)
|
||||
spriteDog:setPosition(cocos2d.CCPoint(0, winSize.height/4*3))
|
||||
layerFarm:addChild(spriteDog)
|
||||
|
||||
animFrames = cocos2d.CCMutableArray_CCSpriteFrame__:new(2)
|
||||
animFrames:addObject(frame0)
|
||||
animFrames:addObject(frame1)
|
||||
|
||||
animation = cocos2d.CCAnimation:animationWithName("wait", 0.5, animFrames)
|
||||
|
||||
animate = cocos2d.CCAnimate:actionWithAnimation(animation, false);
|
||||
spriteDog:runAction(cocos2d.CCRepeatForever:actionWithAction(animate))
|
||||
|
||||
|
||||
-- add a popup menu
|
||||
|
||||
function menuCallbackClosePopup()
|
||||
menuPopup:setIsVisible(false)
|
||||
end
|
||||
|
||||
menuPopupItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
|
||||
menuPopupItem:setPosition( cocos2d.CCPoint(0, 0) )
|
||||
menuPopupItem:registerScriptHandler("menuCallbackClosePopup")
|
||||
menuPopup = cocos2d.CCMenu:menuWithItem(menuPopupItem)
|
||||
menuPopup:setPosition( cocos2d.CCPoint(winSize.width/2, winSize.height/2) )
|
||||
menuPopup:setIsVisible(false)
|
||||
layerMenu:addChild(menuPopup)
|
||||
|
||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
||||
|
||||
function menuCallbackOpenPopup()
|
||||
menuPopup:setIsVisible(true)
|
||||
end
|
||||
|
||||
menuToolsItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu1.png","menu1.png")
|
||||
menuToolsItem:setPosition( cocos2d.CCPoint(0, 0) )
|
||||
menuToolsItem:registerScriptHandler("menuCallbackOpenPopup")
|
||||
menuTools = cocos2d.CCMenu:menuWithItem(menuToolsItem)
|
||||
menuTools:setPosition( cocos2d.CCPoint(30, 40) )
|
||||
layerMenu:addChild(menuTools)
|
||||
|
||||
|
||||
function tick()
|
||||
|
||||
point = spriteDog:getPosition();
|
||||
|
||||
if point.x > winSize.width then
|
||||
point.x = 0
|
||||
spriteDog:setPosition(point)
|
||||
else
|
||||
point.x = point.x + 1
|
||||
spriteDog:setPosition(point)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false)
|
||||
|
||||
-- run
|
||||
|
||||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame)
|
|
@ -8,9 +8,23 @@ win32/main.cpp
|
|||
Classes/AppDelegate.h
|
||||
Classes/AppDelegate.cpp
|
||||
|
||||
[! if ! CC_USE_LUA]
|
||||
Classes/HelloWorldScene.h
|
||||
Classes/HelloWorldScene.cpp
|
||||
[! endif]
|
||||
|
||||
[! if CC_USE_LUA]
|
||||
Resource/Default.png
|
||||
Resource/crop.png
|
||||
Resource/farm.jpg
|
||||
Resource/land.png
|
||||
Resource/menu2.png
|
||||
Resource/Icon.png
|
||||
Resource/dog.png
|
||||
Resource/hello.lua
|
||||
Resource/menu1.png
|
||||
[! else]
|
||||
Resource/CloseSelected.png
|
||||
Resource/CloseNormal.png
|
||||
Resource/HelloWorld.png
|
||||
[! endif]
|
||||
|
|
Loading…
Reference in New Issue