我正在尝试在 Corona 中使用 StoryBoard API。但是,我的按钮触摸事件根本不起作用。你能看看我的代码并帮助我吗?
main.lua:
local storyboard = require "storyboard"
storyboard.gotoScene( "scene1", "fade", 500 )
场景1:
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local image
-- Touch event listener for background image
local function onSceneTouch( self, event )
if event.phase == "began" then
storyboard.gotoScene( "scene2", "fade", 400 )
return true
end
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local screenGroup = self.view
image = display.newImage( "bird.png" )
screenGroup:insert( image )
image.touch = onSceneTouch
print( "\n1: createScene event")
end
function scene:enterScene( event )
print( "1: enterScene event" )
end
function scene:exitScene( event )
print( "1: exitScene event" )
-- remove touch listener for image
image:removeEventListener( "touch", image )
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
print( "((destroying scene 1's view))" )
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
我的第二个场景也是这样。但是,当我触摸图像时,它不会进入第二个场景。