赞
踩
开发工具:Cocos Code IDE
开发环境:MAC
项目效果:显示一张图片
项目代码:
- require "Cocos2d"
-
- -- cclog
- local cclog = function(...)
- print(string.format(...))
- end
-
- -- for CCLuaEngine traceback
- function __G__TRACKBACK__(msg)
- cclog("----------------------------------------")
- cclog("LUA ERROR: " .. tostring(msg) .. "\n")
- cclog(debug.traceback())
- cclog("----------------------------------------")
- return msg
- end
-
- local function setLayer(gameScene)
- local layer = cc.Layer:create()
- layer:setAnchorPoint(0,0)
- gameScene:addChild(layer)
- return layer
- end
-
- ---------------------------
- --@return #Sprite image sprite
- local function setImageSprite(layer)
- local sprite = cc.Sprite:create("dog.png")
- sprite:setPosition(200, 200)
- layer:addChild(sprite)
- end
-
- local function main()
- collectgarbage("collect")
- -- avoid memory leak
- collectgarbage("setpause", 100)
- collectgarbage("setstepmul", 5000)
-
- cc.FileUtils:getInstance():addSearchPath("src")
- cc.FileUtils:getInstance():addSearchPath("res")
-
- local gameScene = cc.Scene:create()
-
- local layer = setLayer(gameScene)
-
- setImageSprite(layer)
-
- cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(480, 320, 0)
-
- if cc.Director:getInstance():getRunningScene() then
- cc.Director:getInstance():replaceScene(gameScene)
- else
- cc.Director:getInstance():runWithScene(gameScene)
- end
- end
-
-
- local status, msg = xpcall(main, __G__TRACKBACK__)
- if not status then
- error(msg)
- end
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。