Quick Cocos2dx 场景转换问题
2024-09-25 11:01:18
项目结构是这样子的:
主场景代码是这样子的:
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 = , align = ui.TEXT_ALIGN_CENTER,
x = display.cx, y = display.cy + ,
listener = function()
print("Start touched")
nexScene = display.newScene("AnotherScene");
CCDirector:sharedDirector():replaceScene(CCTransitionFade:create(, nexScene))
end}) self.item1 = ui.newTTFLabelMenuItem({text = "ABOUT", size = , align = ui.TEXT_ALIGN_CENTER,
x=display.cx, y=display.cy,
listener = function()
print("About touched")
end}) self.item2 = ui.newTTFLabelMenuItem({text = "EXIT", size = , align = ui.TEXT_ALIGN_CENTER,
x=display.cx, y=display.cy-,
listener = function()
print("Exit touched")
game.exit()
end})
self.menu = ui.newMenu({self.item0,self.item1,self.item2})
self.layer:addChild(self.menu)
end function MainScene:onEnter()
self.layer:setTouchEnabled(true)
end function MainScene:onTouch(event, x, y)
print(event)
end function MainScene:onExit()
end return MainScene
新场景代码是这样子的:
local AnotherScene = class("AnotherScene", function()
return display.newScene("AnotherScene")
end) function AnotherScene:ctor()
print("Constructor of AnotherScene")
end function AnotherScene:onEnter()
print("Custom AnotherScene:onEnter")
ui.newTTFLabel({text = "AnotherScene", size = , 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(, nexScene))
然后就正常了。
如下:
这也许就是脚本语言的便利与不便利之处了。
最新文章
- #26 fibonacci seqs
- 通过js调用android原生方法
- Java关于IO流的介绍
- 分享Kali Linux 2016.2第48周虚拟机
- Android 的EditText实现不可编辑
- java 网络编程 模拟browser
- delphi 实现微信开发
- LINQ之路(1):LINQ基础
- 流畅python学习笔记:第十一章:抽象基类
- 第二十章 Django数据库实战
- Spring自定义类扫描器 ClassPathScanningCandidateComponentProvider
- 题解 CF540D 【Bad Luck Island】
- get通配符
- adb 查看包名或其他
- 为 github markdown 文件生成目录(toc)
- 虚拟机性能监控与故障处理工具------JDK的命令行工具
- Qt动态布局
- entityFramework 中decimal精度缺失问题
- November 01st, 2017 Week 44th Wednesday
- maven打包部署到私服
热门文章
- sql-删除delete涉及到三个表,这个时候就要使用from,比如这样
- 使用内链接(A a inner join B b on a.xx = b.xx)查询2个表中某一列的相同的字段。
- win10怎么启用网络发现,网络发现已关闭怎么办
- FileSystemXmlApplicationContext方法的绝对路径问题
- Android内核驱动程序的编写和编译过程
- <;link rel=";stylesheet"; href=";3.css";/>; 链接方式
- java 方法的重载的语法规则
- CSS3边框
- 【linux系统学习】计算机硬件核心知识
- 用MyEclipse自动生成hibernate映射文件和实体类