当事件循环的if else语句变量匹配时,前往场景的Corona。

我有这样的代码:

local quotetap = 30
function changet()
if tImage then tImage:removeSelf() end
if counterBlock then counterBlock:removeSelf() end

tImage = display.newImage( "images/tFaces_"..math.random(6)..".jpg",      264, 280 )
tImage.x = display.contentWidth * 0.5
tImage.y = display.contentHeight * 0.5
counter = counter + 1

counterBlock = display.newText(counter, 30, 30, native.systemFont, 25)
counterBlock.x = display.contentWidth /7 *6
counterBlock.y = display.contentHeight /10

tImage:addEventListener("tap", changet)
end

我想要加入下面的代码:

if (counter == quotetap) then
composer.gotoScene( "scenes.nextlevel", "fade", 500 )
end

请注意,计数器正常工作。但是当我添加这段代码后,我注意到当计数器达到30时出现了摩擦。但是它没有像预期的那样更改场景。经过短暂的暂停后,它只是继续计数。

点赞
用户2305605
用户2305605

你需要在 params 表格中包含参数(time, effect)。查看这里 https://docs.coronalabs.com/api/library/composer/gotoScene.html

改为:

local options = {
    effect = "fade",
    time = 500,
}
composer.gotoScene( "scenes.nextlevel", options )

或者:

composer.gotoScene("scenes.nextlevel", { effect = "fade", time = 500, })
2015-09-11 03:31:20
用户4500704
用户4500704
ah I've figured out what's happening. Sorry for the meaningless question. Seems it actually is changing scenes. The scene i switch to is currently blank. So it actually is switching, and not clearing the old objects. So it appears that it is staying on the same scene, when it actually is not.

噢,我明白发生了什么了。抱歉之前问的问题毫无意义。看来它实际上正在切换场景。我切换到的场景目前是空白的。所以实际上是在切换,而不是清除旧的对象。所以它看起来停留在同一场景,实际上并不是。

2015-09-11 20:20:57