项目结构是这样子的:

主场景代码是这样子的:

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))

然后就正常了。

如下:

这也许就是脚本语言的便利与不便利之处了。

最新文章

  1. #26 fibonacci seqs
  2. 通过js调用android原生方法
  3. Java关于IO流的介绍
  4. 分享Kali Linux 2016.2第48周虚拟机
  5. Android 的EditText实现不可编辑
  6. java 网络编程 模拟browser
  7. delphi 实现微信开发
  8. LINQ之路(1):LINQ基础
  9. 流畅python学习笔记:第十一章:抽象基类
  10. 第二十章 Django数据库实战
  11. Spring自定义类扫描器 ClassPathScanningCandidateComponentProvider
  12. 题解 CF540D 【Bad Luck Island】
  13. get通配符
  14. adb 查看包名或其他
  15. 为 github markdown 文件生成目录(toc)
  16. 虚拟机性能监控与故障处理工具------JDK的命令行工具
  17. Qt动态布局
  18. entityFramework 中decimal精度缺失问题
  19. November 01st, 2017 Week 44th Wednesday
  20. maven打包部署到私服

热门文章

  1. sql-删除delete涉及到三个表,这个时候就要使用from,比如这样
  2. 使用内链接(A a inner join B b on a.xx = b.xx)查询2个表中某一列的相同的字段。
  3. win10怎么启用网络发现,网络发现已关闭怎么办
  4. FileSystemXmlApplicationContext方法的绝对路径问题
  5. Android内核驱动程序的编写和编译过程
  6. &lt;link rel=&quot;stylesheet&quot; href=&quot;3.css&quot;/&gt; 链接方式
  7. java 方法的重载的语法规则
  8. CSS3边框
  9. 【linux系统学习】计算机硬件核心知识
  10. 用MyEclipse自动生成hibernate映射文件和实体类