【问题标题】:Corona SDK composer - changing scenes doesn't workCorona SDK 作曲家 - 改变场景不起作用
【发布时间】:2015-11-16 19:25:09
【问题描述】:

我对 Corona SDK 作曲家 API 有一点问题。我有 3 个 .lua 文件 - main.lua、character.lua 和 job.lua。问题是,当我运行游戏时,它会自动转换到 character.lua 并且一切都很好。然后我正在转换到 job.lua,它也可以正常工作,但是当我试图回到 character.lua 时,什么也没有发生(背景没有改变)。这就是它的样子:

main.lua:

local composer = require("composer")
composer.gotoScene("character")

character.lua:

local composer = require( "composer" )

local scene = composer.newScene()

-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------

-- local forward references should go here

-- -------------------------------------------------------------------------------


-- "scene:create()"
function scene:create( event )

    local sceneGroup = self.view

    -- Initialize the scene here.
    -- Example: add display objects to "sceneGroup", add touch listeners, etc.
  
local widget = require("widget")


local bottomTabButtons ={
    {  width=32, height=32, defaultFile="character.png", overFile="character_active.png", selected="true"},
    {  width=32, height=32, defaultFile="job.png", overFile="job_active.png", onPress=function() composer.gotoScene( "job" )end},
}
local bottomBar = widget.newTabBar{
     top = display.contentHeight-40,

    buttons = bottomTabButtons
}




end


-- "scene:show()"
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is still off screen (but is about to come on screen).
    elseif ( phase == "did" ) then
        -- Called when the scene is now on screen.
        -- Insert code here to make the scene come alive.
        -- Example: start timers, begin animation, play audio, etc.
    end
end


-- "scene:hide()"
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is on screen (but is about to go off screen).
        -- Insert code here to "pause" the scene.
        -- Example: stop timers, stop animation, stop audio, etc.
    elseif ( phase == "did" ) then
        -- Called immediately after scene goes off screen.
    end
end


-- "scene:destroy()"
function scene:destroy( event )

    local sceneGroup = self.view

    -- Called prior to the removal of scene's view ("sceneGroup").
    -- Insert code here to clean up the scene.
    -- Example: remove display objects, save state, etc.
end


-- -------------------------------------------------------------------------------

-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

-- -------------------------------------------------------------------------------

return scene

job.lua:

local composer = require( "composer" )
local widget = require("widget")
local scene = composer.newScene()

-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------

-- local forward references should go here

-- -------------------------------------------------------------------------------


-- "scene:create()"
function scene:create( event )

    local sceneGroup = self.view

    -- Initialize the scene here.
    -- Example: add display objects to "sceneGroup", add touch listeners, etc.
    local background = display.newImage("background.png")
    background.x=display.contentCenterX
    background.y=display.contentCenterY
    background.height=display.contentHeight
    background.width=display.contentWidth

      local function gotoCharacter(event)
        composer.gotoScene("character")
        print('asd')
    end

    local bottomTabButtons ={
    {  width=32, height=32, defaultFile="character.png", overFile="character_active.png", onPress=function() composer.gotoScene( "character" ) end},
    {  width=32, height=32, defaultFile="job.png", overFile="job_active.png", selected="true"},
    }
        

    local bottomBar = widget.newTabBar{
         top = display.contentHeight-40,

        buttons = bottomTabButtons
    }

 
end


-- "scene:show()"
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is still off screen (but is about to come on screen).


    elseif ( phase == "did" ) then
        -- Called when the scene is now on screen.
        -- Insert code here to make the scene come alive.
        -- Example: start timers, begin animation, play audio, etc.

    end
end


-- "scene:hide()"
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Called when the scene is on screen (but is about to go off screen).
        -- Insert code here to "pause" the scene.
        -- Example: stop timers, stop animation, stop audio, etc.

    elseif ( phase == "did" ) then
        -- Called immediately after scene goes off screen.

    end
end


-- "scene:destroy()"
function scene:destroy( event )

    local sceneGroup = self.view

    -- Called prior to the removal of scene's view ("sceneGroup").
    -- Insert code here to clean up the scene.
    -- Example: remove display objects, save state, etc.
end


-- -------------------------------------------------------------------------------

-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

-- -------------------------------------------------------------------------------

return scene

提前致谢!

【问题讨论】:

    标签: sdk lua coronasdk


    【解决方案1】:

    问题是您没有将显示对象插入到场景组中。这就是为什么它没有被删除。将所有对象插入场景组。

    例如,

    local background = display.newImage("background.png")
    background.x=display.contentCenterX
    background.y=display.contentCenterY
    background.height=display.contentHeight
    background.width=display.contentWidth
    
    sceneGroup:insert(background) 
    

    --- 这就是变化。以同样的方式将所有对象插入到该组中。

    【讨论】:

      猜你喜欢
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2017-03-13
      • 2016-04-12
      • 1970-01-01
      相关资源
      最近更新 更多