我在根据事件侦听器和全局变量更改场景时遇到问题。
基本上,在做出某些选择后场景会重复,这会增加变量finalcount
,因为需要限制选择的级别。当计数器达到 4 时,场景应该改变,这使得finalcountscene
变量等于 1。这应该触发场景的改变,而不是scenechangeworking
5 次。所以功能有效,但场景不会改变。请帮忙!代码可以在下面找到。
local function scenechangecount (event)
if gameState.finalcountscene == 1 then
Runtime:removeEventListener( "enterFrame", maincount )
director:changeScene ("gamemenu")
print("scene change working")
Runtime:removeEventListener( "enterFrame", scenechangecount)
end
end
local function maincount (event)
if gameState.finalcount == 4 then
gameState.finalcountscene = 1
print("working",gameState.finalcount, "scene count", gameState.finalcountscene)
Runtime:removeEventListener( "enterFrame", maincount)
elseif gameState.finalcount == 3 then
gameState.finalcount = gameState.finalcount +1
print(gameState.finalcount)
local message = display.newImage ("images/message.png")
message.x = display.contentWidth/2 - display.contentWidth/6
message.y = display.contentHeight/2 - display.contentHeight/4 - display.contentHeight/18
localGroup:insert(message)
Runtime:removeEventListener( "enterFrame", maincount )
else
gameState.finalcount = gameState.finalcount + 1
print(gameState.finalcount)
Runtime:removeEventListener( "enterFrame", maincount )
end
end
Runtime:addEventListener ("enterFrame", scenechangecount)
Runtime:addEventListener ("enterFrame", maincount)