\"name\": \"redDefense\",122)\">\"width\": 1920,122)\">\"height\": 1080,122)\">\" />
大佬教程收集整理的这篇文章主要介绍了3、cocos2d-Lua的运行流程与场景,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
{可以看到 "entry": "src/main.lua",也就是说入口文件是main.lua,进而打开main.lua:
"init_cfg": {
"isLandscape": true,
"isWindowTop": false,122)">"name": "redDefense",122)">"width": 1920,122)">"height": 1080,122)">"entry": "src/main.lua",122)">"consolePort": 6050,122)">"uploadPort": 6060,122)">"debugPort": 10000,122)">"forWARDConsolePort": 10089,122)">"forWARDUploadPort": 10091
},122)">"simulator_screen_size": [
{
"title": "iPhone 3Gs (480x320)",255)">480,255)">320
BACkground-color:inherit; color:rgb(0,
{
"iPhone 4 (960x640)",255)">960,255)">640
"iPhone 5 (1136x640)",255)">1136,0)">"iPad (1024x768)",255)">1024,255)">768
"iPad ReTina (2048x1536)",255)">2048,255)">1536
"Android (800x480)",255)">800,255)">480
"Android (854x480)",255)">854,0)">"Android (1280x720)",255)">1280,255)">720
"Android (1920x1080)",255)">1080
}
]
}
cc.FileUtils:geTinstance():setPopupNotify(false)执行main函数,main函数里加载MyApp创建并运行,进而打开MyApp.lua:
addSearchPath("src/")
"res/")
require "config"
"cocos.init"
local function @H_807_207@main()
require("app.MyApp"):create():run()
end
local status,@H_30_235@msg = xpcall(@H_30_235@main,__G__TRACKBACK__)
if not status then
print(@H_30_235@msg)
end
@H_30_235@myApp = class("MyApp",43)">load("mvc").AppBase)这里就有点看头,MyApp仅仅是继承自AppBase,onCreate函数只是初始化了下随机数种子,也就意味着更多的操作在AppBase中,我们打开分析:
function @H_30_235@myApp:onCreate()
@H_365_160@math.randomseed(os.time())
return @H_30_235@myApp
AppBase = "AppBase")在前面的分析中知道main.lua是执行的是App的run函数,作为基类的AppBase,当然也要被调用run函数,因此直接看run函数:主要是创建并进入场景initScenename,如果run的参数没有指定开始的场景则使用默认场景defaultScenename,默认场景在构造函数的时候被初始化为MainScene,也就是说场景默认将从MainScene开始。
AppBase:ctor(configs)
self.configs_ = {
viewsRoot = "app.views",
@H_10_164@modelsRoot = "app.models",43)">defaultScenename = "MainScene",
}
for k,153)">v in pairs(configs or {}) do
configs_[k] = v
if type(configs_.viewsRoot) ~= "table" viewsRoot = {viewsRoot}
@H_129_412@modelsRoot) ~= @H_129_412@modelsRoot = {@H_335_389@modelsRoot}
DEBUG > 1 dump(configs_,0)">"AppBase configs")
CC_SHOW_FPS Director:setDisplayStats(true)
-- event
self:onCreate()
run(initScenename)
initScenename = initScenename or defaultScenename
enterScene(initScenename)
enterScene(scenename,transition,255)">time,255)">more)
view = createView(scenename)
view:showWithScene(view
createView(name)
_,153)">root ipairs(viewsRoot) local packagename = String.format("%s.%s",153)">root,153)">view = function()
return require(package@R_674_8313@
end,128)">function(@H_298_335@msg)
if not find(@H_298_335@msg,0)">"'%s' not found:",packagename)) "load view error: ",128)"> end)
t = type(view)
if and (t == or "userdata") return view:create(self,@R_674_8313@
end
error("AppBase:createView() - not found view \"%s\" in search paths \"%s\"",
name,0)">table.concat(viewsRoot,0)">",")),255)">0)
AppBase
run('PlayScene')那么项目启动后会直接进入PlayScene场景,而不再是默认的MainScene场景。
end
@H_451_320@mainScene:-- add BACkground image
display.newSprite("MainSceneBg.jpg")
:@H_10_164@move(center)
:addTo(self)
-- add play button
playButton = @H_1_173@menuItemImage:create("PlayButton.png",0)">"PlayButton.png")
:onClicked(function()
self:getApp():enterScene("PlayScene")
end)
@H_1_173@menu:playButton)
:cx,43)">cy - 200)
:self)
@H_30_235@mainScene
PlayScene = "PlayScene",43)">ViewBase)PlayScene场景创建游戏逻辑视图GameView并调用start函数开始游戏,绑定了一个游戏结束的事件,这个事件会在GameView中在触发游戏结束逻辑时发生,PlayScene由于绑定了该事件,则会在游戏结束时调用其绑定的回调事件,以显示战绩和分数,显示一个退出按钮,退出按钮事件为进入MainScene场景。
GameView = import(".GameView")
PlayScene:-- create game view and add it to stage
gameView_ = GameView:create()
:addEventListener(GameView.events.PLAYER_DEAD_EVENT,0)">handler(self,43)">onPlayerDead))
:start()
:onPlayerDead(event)
-- add game over text
text = "You killed %d bugs",43)">gameView_:getKills())
Label:createWithSystemFont(text,0)">"Arial",255)">96)
:align(CENTER,128)">-- add exit button
exitButton = "ExitButton.png",0)">"ExitButton.png")
:@H_469_944@"MainScene")
exitButton)
:PlayScene
"init_cfg": {可以看到 "entry": "src/main.lua",也就是说入口文件是main.lua,进而打开main.lua:
"isLandscape": true,122); font-weight:bold">"isWindowTop": false,122); font-weight:bold">"name": "redDefense",122); font-weight:bold">"width": "height": "entry": "src/main.lua",122); font-weight:bold">"consolePort": "uploadPort": "debugPort": "forWARDConsolePort": "forWARDUploadPort": "simulator_screen_size": [
{
"title": "iPhone 3Gs (480x320)",0); font-weight:bold">"iPhone 4 (960x640)",0); font-weight:bold">"iPhone 5 (1136x640)",0); font-weight:bold">"iPad (1024x768)",0); font-weight:bold">"iPad ReTina (2048x1536)",0); font-weight:bold">"Android (800x480)",0); font-weight:bold">"Android (854x480)",0); font-weight:bold">"Android (1280x720)",0); font-weight:bold">"Android (1920x1080)",255)">}
]
}
false)执行main函数,main函数里加载MyApp创建并运行,进而打开MyApp.lua:
"src/")
"res/")
"config"
"cocos.init"
local function "app.MyApp"):end
local if not then
end
"MyApp",0); font-weight:bold">"mvc").function return @H_30_235@myApp这里就有点看头,MyApp仅仅是继承自AppBase,onCreate函数只是初始化了下随机数种子,也就意味着更多的操作在AppBase中,我们打开分析:
"AppBase")在前面的分析中知道main.lua是执行的是App的run函数,作为基类的AppBase,当然也要被调用run函数,因此直接看run函数:主要是创建并进入场景initScenename,如果run的参数没有指定开始的场景则使用默认场景defaultScenename,默认场景在构造函数的时候被初始化为MainScene,也就是说场景默认将从MainScene开始。
"app.views",0); font-weight:bold">"app.models",0); font-weight:bold">"MainScene",128); font-weight:bold">for in or {}) do
if "table" "AppBase configs")
true)
-- event
or local "%s.%s",128); font-weight:bold">function()
return require(package@R_674_8313@
end,128); font-weight:bold">function(if not "'%s' not found:",packagename)) "load view error: ",128); font-weight:bold"> end)
if and (or "userdata") return view:create(self,@R_674_8313@
end
"AppBase:createView() - not found view \"%s\" in search paths \"%s\"",0); font-weight:bold">",")),153)">AppBase
'PlayScene')那么项目启动后会直接进入PlayScene场景,而不再是默认的MainScene场景。
end
"PlayScene",0); font-weight:bold">".GameView")PlayScene场景创建游戏逻辑视图GameView并调用start函数开始游戏,绑定了一个游戏结束的事件,这个事件会在GameView中在触发游戏结束逻辑时发生,PlayScene由于绑定了该事件,则会在游戏结束时调用其绑定的回调事件,以显示战绩和分数,显示一个退出按钮,退出按钮事件为进入MainScene场景。
-- create game view and add it to stage
gameView_ = GameView:addEventListener(GameView.-- add game over text
"You killed %d bugs",0); font-weight:bold">"Arial",128); font-style:italic">-- add exit button
"ExitButton.png",0); font-weight:bold">"ExitButton.png")
:"MainScene")
PlayScene
以上是大佬教程为你收集整理的3、cocos2d-Lua的运行流程与场景全部内容,希望文章能够帮你解决3、cocos2d-Lua的运行流程与场景所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。