1.建立一个空项目:
2. 点击Open运行可以得到
3. 项目结构图
debug.log文件:主要是设置debug窗口的一些属性日志文件
config.json:主要是设置运行的一些参数和运行模拟器设置,比较重要的是"entry": "src/main.lua" ,程序的入口处
.project:关于项目的文件
src:代码文件夹
res:资源文件夹
frameworks:运行所需要的一些C/C++库或者bat文件等,一般不用管。
4. 程序入口src/main.lua
function __G__TRACKBACK__(errorMessage)
print("----------------------------------------")
print("LUA ERROR: " .. tostring(errorMessage) .. "\n")
print(debug.traceback("", 2))
print("----------------------------------------")
end
package.path = package.path .. ";src/"
cc.FileUtils:getInstance():setPopupNotify(false)
require("app.MyApp").new():run()
require("app.MyApp").new():run()这句话调用了src/app/MyApp.lua文件
5.MyApp.lua文件
require("config")
require("cocos.init")
require("framework.init")
local MyApp = class("MyApp", cc.mvc.AppBase)
function MyApp:ctor()
MyApp.super.ctor(self)
end
function MyApp:run()
cc.FileUtils:getInstance():addSearchPath("res/")
self:enterScene("MainScene")
end
return MyApp
这个文件调用了三个文件config cocos.init framework.init 进行初始化,定义了一个MyApp类,这个类继承了cc.mvc.AppBase这个类
定义了一个构造方法ctor()
cc.FileUtils:getInstance():addSearchPath("res/")定义的是资源的路径,
self:enterScene("MainScene") 进入主场景,为什么路径不是src/app/scenes,是因为而AppBase.lua的enterScene这个方法中有local scenePackageName = self.packageRoot .. ".scenes." .. sceneName.
6.MainScene.lua
local MainScene = class("MainScene", function()
return display.newScene("MainScene")
end)
function MainScene:ctor()
cc.ui.UILabel.new({
UILabelType = 2, text = "北方有佳人。绝世而独立。", size = 18})
:align(display.CENTER, display.cx, display.cy)
:addTo(self)
end
function MainScene:onEnter()
end
显示的UI控件