Quick cocos2dx scenario conversion problem

Source: Internet
Author: User

The project structure is like this:

The main scenario code is like this:

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

 

The code for the new scenario is like this:

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

 

However, after clicking start, a new black scenario is displayed. The debug content is as follows:

No printing at allAnotherscene. Lua Ctor ()AndOnenter ()Content.

After checking the source code of qucik cocos2dx, we found thatDisplay. newscene ("anotherscene ")A new name named"Anotherscene"OfCcscene,

Instead of retrievingAnotherscene. Lua, As follows:

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

 

The listener code of item0 is as follows:

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

Then it is normal.

As follows:

 

This may be the convenience and inconvenience of the script language.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.