【发布时间】:2017-05-09 04:21:19
【问题描述】:
我使用 gotoscene 从 menu.lua 转到 game.lua。在 game.lua 结束时,我再次从 game.lua 过渡到 menu.lua。在 scene:show in menu.lua 下,我删除了游戏场景。然后,当我回到 game.lua 时,场景中的所有内容:显示都重复了两次。场景:创建仍然只有一次。
知道为什么会这样吗?
谢谢。
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
print("does this print once or twice?")
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
physics.start()
gameLoopTimer = timer.performWithDelay( 1750, gameLoop, 0 )
-- Start the music!
audio.play( musicTrack, { channel=1, loops=-1 } )
audio.setVolume( 0, { channel=1 } )
-- Code here runs when the scene is entirely on screen
end
end
composer.gotoscene(game.lua) 由在创建阶段调用的 menuDrawer 函数创建的多个对象之一的点击调用。
local function menuDrawer()
....
for i = 1, #menuLetters, 1 do
....
local Letterbackground = display.newRoundedRect(sceneGroup, Letterbackgroundx, Letterbackgroundy, 100, 125, 10 )
....
Letterbackground:addEventListener( "tap", gotoGame )
end
EventListener 永远不会被删除,因为它只由函数内的局部变量定义。这会导致问题吗?
如果您需要更多信息,请告诉我。
【问题讨论】:
-
请注意:为了确认这一点,我只是将 print("something") 放在 scene:show 下。
标签: coronasdk