项目结构是这样子的:

主场景代码是这样子的:

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. Delphi XE2 生成的.exe 在未安装有Delphi的电脑上运行提示 “丢失 rtl160.bpl”

    解决方案: XE2中加入了多平台的概念,默认的Release模式,也是带包编译,带运行时库的,所以,需要手工设置一下工程选项: 打开工程以后,Project-->Options-->左侧树 ...

  2. php-redis 下载地址

    http://windows.php.net/downloads/pecl/snaps/redis/2.2.5/

  3. C++ 字符串字面值

    C++ 字符串字面值 C++ 基本字符串类型 C++ 字符串类型 char 和 wchar_t c11 新增了 char16_t 和 char32_t 例子: wchat_t title[] = L& ...

  4. FileSystemXmlApplicationContext方法的绝对路径问题

    public AgentServer(Socket c,String confDir) { this.client = c; ApplicationContext ac = new FileSyste ...

  5. Oulipo HDU 1686 KMP模板

    题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...

  6. servlet中路径的获取

    1.获取项目的绝对路径 可以request.getRealPath("/"),但是这个方法已经废弃了,最好用this.getServletContext().getRealPath ...

  7. 初探JavaScript魅力

    <style> #div1{width:200px; height:200px; background:red;} </style> </head> <scr ...

  8. java 数据流

    Example10_11.java import java.io.*; public class Example10_11 { public static void main(String args[ ...

  9. java 数组流

    Example10_10.java import java.io.*; public class Example10_10 { public static void main(String args[ ...

  10. Linux中java项目环境部署,简单记录一下

    这里只是简单的记录一下linux环境下面如何快速的搭配好环境,使你的项目能在linux环境上面运行. 很多时候,我们都是用windows环境进行配置调试的,而真正很多服务器都是在linux服务器上面的 ...