后退按钮无法导航到所需的场景
Back button does not navigate to required scene
在 "tap",firstBar1.lua 转到 scene1.lua。如果在 scene1 超时期间没有点击,那么它将移动到 scene2 等等; scene1 有一个指向 firstBar1 的返回按钮。它返回了片刻,然后继续到场景 2。它需要停留在 firstBar1 上,直到有另一个点击。我尝试了各种按钮代码,这是我能得到的最好结果。点击后退按钮后打印 ("firstBar1") 不起作用。
-- firstBar1.lua
-----------------------------------------------------
local composer = require ("composer")
print ("firstBar1")
local scene = composer.newScene()
function scene:create(event)
local screenGroup = self.view
local widget = require ("widget")
local function onScene1BtnRelease()
composer.gotoScene("scene1", "fade", 40)
return true
end
image1 = "images/staveBlankgrey2.png"
local scene1Btn = widget.newButton{
defaultFile = image1,
width = 480, height = 320,
onRelease = onScene1BtnRelease
}
screenGroup:insert(scene1Btn)
end
scene:addEventListener( "create", scene)
scene:addEventListener( "show", scene)
scene:addEventListener( "hide", scene)
scene:addEventListener( "destroy", scene)
return scene
场景 1:
-- scene1.lua
--------------------------------------------------------------------
local mydata = require ("mydata")
local composer = require ( "composer")
local scene = composer.newScene()
local function showScene2()
local options = {
effect = "slideLeft",
time = 130,
}
composer.gotoScene("scene2", options)
end
-- create scene 3
function scene:createScene ( event )
local sceneGroup = self.view
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
-- will
if ( phase == "will") then
data = data + 1
if data == 5 then
sub = sub + 1
data = 1
end
if sub == 3 then
section = section + 1
sub = 1
data = 1
end
stave = display.newImage( "images/staveBlankgrey2.png", 240, 160 )
note1 = display.newImage( "images/crDown.png", 130, 141 )
count = display.newImage( workoutTable[section][sub][data], 60, 40 )
sceneGroup:insert( stave )
sceneGroup:insert( note1 )
sceneGroup:insert( count )
-- goBackBtn
local widget = require ("widget")
local button = display.newImage("images/goBackBtn.png")
button.x = display.contentWidth / 2
button.y = display.contentHeight - 60
sceneGroup:insert( button )
function button:tap(event)
composer.gotoScene("firstBar1", "fade", 30)
end
button:addEventListener("tap", button)
print ("button 1 pressed")
sceneGroup:insert( button )
return true
-- did
elseif ( phase == "did") then
local function showScene2()
local options = {
effect = "slideLeft",
time = 30,
}
composer.gotoScene( "scene2", options )
end
timer.performWithDelay(tempo, showScene2 )
end
end
-- hide / destroy
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
end
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
return scene
如果我遗漏了什么,你能告诉我在哪里添加吗?谢谢。
处理后退按钮触摸时,需要取消进入下一个场景的计时器。
在模块的顶部声明一个变量来存储计时器的句柄:
local sessionTimer
然后当你启动计时器时:
sessionTimer = timer.performWithDelay(tempo, showScene2 )
最后,如果您在计时器结束前离开场景,也许在您的按钮处理程序中,执行:
timer.cancel( sessionTimer )
或类似的东西。
在 "tap",firstBar1.lua 转到 scene1.lua。如果在 scene1 超时期间没有点击,那么它将移动到 scene2 等等; scene1 有一个指向 firstBar1 的返回按钮。它返回了片刻,然后继续到场景 2。它需要停留在 firstBar1 上,直到有另一个点击。我尝试了各种按钮代码,这是我能得到的最好结果。点击后退按钮后打印 ("firstBar1") 不起作用。
-- firstBar1.lua
-----------------------------------------------------
local composer = require ("composer")
print ("firstBar1")
local scene = composer.newScene()
function scene:create(event)
local screenGroup = self.view
local widget = require ("widget")
local function onScene1BtnRelease()
composer.gotoScene("scene1", "fade", 40)
return true
end
image1 = "images/staveBlankgrey2.png"
local scene1Btn = widget.newButton{
defaultFile = image1,
width = 480, height = 320,
onRelease = onScene1BtnRelease
}
screenGroup:insert(scene1Btn)
end
scene:addEventListener( "create", scene)
scene:addEventListener( "show", scene)
scene:addEventListener( "hide", scene)
scene:addEventListener( "destroy", scene)
return scene
场景 1:
-- scene1.lua
--------------------------------------------------------------------
local mydata = require ("mydata")
local composer = require ( "composer")
local scene = composer.newScene()
local function showScene2()
local options = {
effect = "slideLeft",
time = 130,
}
composer.gotoScene("scene2", options)
end
-- create scene 3
function scene:createScene ( event )
local sceneGroup = self.view
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
-- will
if ( phase == "will") then
data = data + 1
if data == 5 then
sub = sub + 1
data = 1
end
if sub == 3 then
section = section + 1
sub = 1
data = 1
end
stave = display.newImage( "images/staveBlankgrey2.png", 240, 160 )
note1 = display.newImage( "images/crDown.png", 130, 141 )
count = display.newImage( workoutTable[section][sub][data], 60, 40 )
sceneGroup:insert( stave )
sceneGroup:insert( note1 )
sceneGroup:insert( count )
-- goBackBtn
local widget = require ("widget")
local button = display.newImage("images/goBackBtn.png")
button.x = display.contentWidth / 2
button.y = display.contentHeight - 60
sceneGroup:insert( button )
function button:tap(event)
composer.gotoScene("firstBar1", "fade", 30)
end
button:addEventListener("tap", button)
print ("button 1 pressed")
sceneGroup:insert( button )
return true
-- did
elseif ( phase == "did") then
local function showScene2()
local options = {
effect = "slideLeft",
time = 30,
}
composer.gotoScene( "scene2", options )
end
timer.performWithDelay(tempo, showScene2 )
end
end
-- hide / destroy
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
end
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
return scene
如果我遗漏了什么,你能告诉我在哪里添加吗?谢谢。
处理后退按钮触摸时,需要取消进入下一个场景的计时器。
在模块的顶部声明一个变量来存储计时器的句柄:
local sessionTimer
然后当你启动计时器时:
sessionTimer = timer.performWithDelay(tempo, showScene2 )
最后,如果您在计时器结束前离开场景,也许在您的按钮处理程序中,执行:
timer.cancel( sessionTimer )
或类似的东西。