项目结构是这样子的:

主场景代码是这样子的:

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

然后就正常了。

如下:

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

Quick Cocos2dx 场景转换问题的更多相关文章

  1. Quick Cocos2dx 场景对象基类实现

    从使用Quick-Cocos2d-x搭建一个横版过关游戏(四)拷来个进度条类, 但是由于那个类有个bug,在setProgress里面self.fill是找不到的,所以我改进了一下,代码如下: loc ...

  2. Quick Cocos2dx Action相关

    周末在家除了看犯罪心里和反恐24小时,啥都没干,为毛在家老是不能安安静静的看书学习敲代码?不知道啊 心好累,感觉学习不下去了. 然后公司上午有半天世界杯决赛假,下午回来更新了svn,没啥工作内容,只好 ...

  3. quick cocos2d-x 入门---井字棋

    学习quick cocos2d-x 第二天 ,使用quick-x 做了一个井字棋游戏 . 我假设读者已经 http://wiki.quick-x.com/doku.php?id=zh_cn阅读了这个链 ...

  4. (10)场景转换(Transitions)

    Cocos2d-x最爽的一个特性之一就是提供了在两个不同场景之间直接转换的能力.例如:淡入淡出,放大缩小,旋转,跳动等.从技术上来说,一个场景转换就是在展示并控制一个新场景之前执行一个转换效果. 场景 ...

  5. 【Unity3D】场景转换与退出

    1.场景转换 : 老版本的场景切换用的是Application.LoadLevel([场景名字或者在File->Build settings里面的场景代号]); 新版本的场景转换用到了Scene ...

  6. cocos2d 场景转换的方法执行顺序

    转自:http://shanbei.info/the-cocos2d-scene-conversion-method-execution-order.html 如果你希望在场景转换的过程中使用过渡效果 ...

  7. Mac下搭建quick cocos2d-x编译环境

    一. 我知道在你的电脑中一定已经安装好了Xcode(没有自己下载去吧),打开Xcode,开启"偏好设置"对话框(commond + ,).假设打开之后出现的是这种一个对话框,那么直 ...

  8. Cocos2d-iPhone V3 (2) 场景转换

    Cocos2d-iPhone V3 (2) 场景转换 博客:http://blog.csdn.net/prevention 作者:大锐哥 - 1. 准备工作 创建一个场景会吧? #import &qu ...

  9. Quick Cocos2dx Http通讯

    服务端:Python 通讯协议:Http 参考文章: 1 用python实现一个基本的http server服务器 http://blog.sina.com.cn/s/blog_416e3063010 ...

随机推荐

  1. error while loading shared libraries: libmcrypt.so.4

    /usr/local/php/sbin/php-fpm: error while loading shared libraries: libmcrypt.so.4: cannot open share ...

  2. redhat 安装GCC-4.8.3

    1.下载gcc-4.8.3安装包 gcc各版本浏览地址:http://ftp.gnu.org/gnu/gcc/ yum install gccyum install gcc-c++ 2.将gcc-4. ...

  3. VB 要求对象

    vDoc = WebBrowser1.Document '提示要求对象 Set vDoc = WebBrowser1.Document '正确执行

  4. Object.setPrototypeOf 方法的使用

    将一个指定的对象的原型设置为另一个对象或者null(既对象的[[Prototype]]内部属性). 语法 Object.setPrototypeOf(obj, prototype) 参数 obj 将被 ...

  5. 用GeneratedKeyHolder获得新建数据主键值

    public User createUser(final User user) { final String sql = "insert into sys_users(username, p ...

  6. 【多重背包】 poj 2392

    转自:http://blog.csdn.net/wangjian8006 题目大意:有一头奶牛要上太空,他有很多种石头,每种石头的高度是hi,但是不能放到ai之上的高度,并且这种石头有ci个将这些石头 ...

  7. 【PHP伪静态】时获取不规则的URL参数

    $url = explode('/', '/article/category-5/status-2/page-3'); $params = array(); foreach ($url as $v) ...

  8. keyboardWillChangeFrameNotification 引发的思考 是的 思考了很久终于出结果

    func keyboardWillChangeFrameNotification(note: NSNotification) { // TODO 添加键盘弹出的事件 let userinfo = no ...

  9. ntp-keygen.c

    这个程序产生加密数据文件使用的的密码,遵循Autokey security protocol和NTPv4.文件名被名字和创建时间组成的头部当做前缀,后面跟有一个类型定义的描述符标签和PEM加密的数据结 ...

  10. python 第三章 字符串-例1

    1.字段宽度和精度 >>>'%.*s' % (10,'Gruido') '     Guido' >>>'%.-*s' % (10,'Gruido') 'Guido ...