axmol/templates/lua-template-runtime/src/main.lua

56 lines
1.4 KiB
Lua
Raw Normal View History

2014-07-14 13:58:21 +08:00
2014-03-11 16:52:06 +08:00
require "Cocos2d"
require "extern"
2014-03-11 16:52:06 +08:00
-- cclog
2014-07-16 20:49:24 +08:00
local cclog = function(...)
2014-03-11 16:52:06 +08:00
print(string.format(...))
end
-- for CCLuaEngine traceback
function __G__TRACKBACK__(msg)
cclog("----------------------------------------")
cclog("LUA ERROR: " .. tostring(msg) .. "\n")
cclog(debug.traceback())
cclog("----------------------------------------")
return msg
2014-03-11 16:52:06 +08:00
end
local function main()
collectgarbage("collect")
-- avoid memory leak
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000)
2014-09-16 16:19:05 +08:00
-- initialize director
local director = cc.Director:getInstance()
--turn on display FPS
director:setDisplayStats(true)
--set FPS. the default value is 1.0/60 if you don't call this
director:setAnimationInterval(1.0 / 60)
2014-07-14 13:58:21 +08:00
cc.FileUtils:getInstance():addSearchPath("src")
cc.FileUtils:getInstance():addSearchPath("res")
2014-05-05 21:04:04 +08:00
cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(480, 320, 0)
2014-07-14 13:58:21 +08:00
--create scene
2014-07-16 21:20:48 +08:00
local scene = require("GameScene")
local gameScene = scene.create()
gameScene:playBgMusic()
2014-07-14 13:58:21 +08:00
2014-07-15 15:07:01 +08:00
if cc.Director:getInstance():getRunningScene() then
cc.Director:getInstance():replaceScene(gameScene)
2014-07-15 15:07:01 +08:00
else
cc.Director:getInstance():runWithScene(gameScene)
2014-07-15 15:07:01 +08:00
end
2014-03-11 16:52:06 +08:00
end
local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
error(msg)
end