日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Quick Cocos2dx 场景转换问题

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Quick Cocos2dx 场景转换问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

項目結構是這樣子的:

主場景代碼是這樣子的:

local MainScene = class("MainScene", function()return display.newScene("MainScene") end)function MainScene:ctor()self.layer = display.newLayer();self:addChild(self.layer)self.item0 = ui.newTTFLabelMenuItem({text = "START", size = 64, align = ui.TEXT_ALIGN_CENTER, x = display.cx, y = display.cy + 50,listener = function()print("Start touched")nexScene = display.newScene("AnotherScene");CCDirector:sharedDirector():replaceScene(CCTransitionFade:create(1, nexScene))end})self.item1 = ui.newTTFLabelMenuItem({text = "ABOUT", size = 64, align = ui.TEXT_ALIGN_CENTER,x=display.cx, y=display.cy,listener = function()print("About touched")end})self.item2 = ui.newTTFLabelMenuItem({text = "EXIT", size = 64, align = ui.TEXT_ALIGN_CENTER, x=display.cx, y=display.cy-50,listener = function()print("Exit touched")game.exit()end})self.menu = ui.newMenu({self.item0,self.item1,self.item2})self.layer:addChild(self.menu) endfunction MainScene:onEnter()self.layer:setTouchEnabled(true) endfunction MainScene:onTouch(event, x, y)print(event) endfunction MainScene:onExit() endreturn MainScene

?百牛信息技術bainiu.ltd整理發布于博客園

新場景代碼是這樣子的:

local AnotherScene = class("AnotherScene", function()return display.newScene("AnotherScene") end)function AnotherScene:ctor()print("Constructor of AnotherScene") endfunction AnotherScene:onEnter()print("Custom AnotherScene:onEnter")ui.newTTFLabel({text = "AnotherScene", size = 64, align = ui.TEXT_ALIGN_CENTER}):pos(display.cx, display.cy):addTo(self) end return AnotherScene

?

可是點擊點擊START之后進入的是一個黑色的新場景,DEBUG內容如下:

根本就沒有打印AnotherScene.lua?ctor()和onEnter()里面的提示內容。

經查驗qucik cocos2dx源碼,發現display.newScene("AnotherScene")新建了一個名為"AnotherScene"的CCScene,

而不是去取AnotherScene.lua,如下:

function display.newScene(name)local scene = CCSceneExtend.extend(CCScene:create())scene.name = name or "<unknown-scene>"return scene end

?

于是將item0的listener的代碼如下:

print("Start touched")local AnotherScene = require("../scripts/app/scenes/AnotherScene")nexScene = AnotherScene:new();CCDirector:sharedDirector():replaceScene(CCTransitionFade:create(1, nexScene))

然后就正常了。

如下:

?

這也許就是腳本語言的便利與不便利之處了。

轉載于:https://www.cnblogs.com/bainiu/p/7592230.html

總結

以上是生活随笔為你收集整理的Quick Cocos2dx 场景转换问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。