mirror of https://github.com/axmolengine/axmol.git
[Lua] fix: HelloLua
This commit is contained in:
parent
d4128975f6
commit
1254d08d5c
|
@ -1,4 +1,13 @@
|
||||||
|
|
||||||
|
-- for CCLuaEngine traceback
|
||||||
|
function __G__TRACKBACK__(msg)
|
||||||
|
print("----------------------------------------")
|
||||||
|
print("LUA ERROR: " .. tostring(msg) .. "\n")
|
||||||
|
print(debug.traceback())
|
||||||
|
print("----------------------------------------")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function main()
|
||||||
-- avoid memory leak
|
-- avoid memory leak
|
||||||
collectgarbage("setpause", 100)
|
collectgarbage("setpause", 100)
|
||||||
collectgarbage("setstepmul", 5000)
|
collectgarbage("setstepmul", 5000)
|
||||||
|
@ -30,12 +39,12 @@ local function creatDog()
|
||||||
spriteDog.isPaused = false
|
spriteDog.isPaused = false
|
||||||
spriteDog:setPosition(0, winSize.height / 4 * 3)
|
spriteDog:setPosition(0, winSize.height / 4 * 3)
|
||||||
|
|
||||||
local animFrames = CCArray:create(2)
|
local animFrames = CCArray:create()
|
||||||
|
|
||||||
animFrames:addObject(frame0)
|
animFrames:addObject(frame0)
|
||||||
animFrames:addObject(frame1)
|
animFrames:addObject(frame1)
|
||||||
|
|
||||||
local animation = CCAnimation:create(animFrames, 0.5)
|
local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.5)
|
||||||
local animate = CCAnimate:create(animation);
|
local animate = CCAnimate:create(animation);
|
||||||
spriteDog:runAction(CCRepeatForever:create(animate))
|
spriteDog:runAction(CCRepeatForever:create(animate))
|
||||||
|
|
||||||
|
@ -101,7 +110,7 @@ local function createLayerFarm()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onTouchMoved(x, y)
|
local function onTouchMoved(x, y)
|
||||||
cclog("onTouchMoved: %0.2f, %0.2f", x, y)
|
-- cclog("onTouchMoved: %0.2f, %0.2f", x, y)
|
||||||
if touchBeginPoint then
|
if touchBeginPoint then
|
||||||
local cx, cy = layerFarm:getPosition()
|
local cx, cy = layerFarm:getPosition()
|
||||||
layerFarm:setPosition(cx + x - touchBeginPoint.x,
|
layerFarm:setPosition(cx + x - touchBeginPoint.x,
|
||||||
|
@ -155,7 +164,7 @@ local function createLayerMenu()
|
||||||
-- add a popup menu
|
-- add a popup menu
|
||||||
local menuPopupItem = CCMenuItemImage:create("menu2.png", "menu2.png")
|
local menuPopupItem = CCMenuItemImage:create("menu2.png", "menu2.png")
|
||||||
menuPopupItem:setPosition(0, 0)
|
menuPopupItem:setPosition(0, 0)
|
||||||
menuPopupItem:registerScriptHandler(menuCallbackClosePopup)
|
menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup)
|
||||||
menuPopup = CCMenu:createWithItem(menuPopupItem)
|
menuPopup = CCMenu:createWithItem(menuPopupItem)
|
||||||
menuPopup:setPosition(winSize.width / 2, winSize.height / 2)
|
menuPopup:setPosition(winSize.width / 2, winSize.height / 2)
|
||||||
menuPopup:setVisible(false)
|
menuPopup:setVisible(false)
|
||||||
|
@ -164,7 +173,7 @@ local function createLayerMenu()
|
||||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
-- add the left-bottom "tools" menu to invoke menuPopup
|
||||||
local menuToolsItem = CCMenuItemImage:create("menu1.png", "menu1.png")
|
local menuToolsItem = CCMenuItemImage:create("menu1.png", "menu1.png")
|
||||||
menuToolsItem:setPosition(0, 0)
|
menuToolsItem:setPosition(0, 0)
|
||||||
menuToolsItem:registerScriptHandler(menuCallbackOpenPopup)
|
menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup)
|
||||||
menuTools = CCMenu:createWithItem(menuToolsItem)
|
menuTools = CCMenu:createWithItem(menuToolsItem)
|
||||||
menuTools:setPosition(30, 40)
|
menuTools:setPosition(30, 40)
|
||||||
layerMenu:addChild(menuTools)
|
layerMenu:addChild(menuTools)
|
||||||
|
@ -186,3 +195,6 @@ local sceneGame = CCScene:create()
|
||||||
sceneGame:addChild(createLayerFarm())
|
sceneGame:addChild(createLayerFarm())
|
||||||
sceneGame:addChild(createLayerMenu())
|
sceneGame:addChild(createLayerMenu())
|
||||||
CCDirector:sharedDirector():runWithScene(sceneGame)
|
CCDirector:sharedDirector():runWithScene(sceneGame)
|
||||||
|
end
|
||||||
|
|
||||||
|
xpcall(main, __G__TRACKBACK__)
|
||||||
|
|
Loading…
Reference in New Issue