0

我正在尝试在 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

我的第二个场景也是这样。但是,当我触摸图像时,它不会进入第二个场景。

4

2 回答 2

2
local function onSceneTouch( self, event )
  if event.phase == "began" then
    storyboard.gotoScene( "scene2", "fade", 400  )
    return true
  end
end

在将任何事件分配给图像等之前,在 onSceneTouch 函数中将“ return true ”更改为“ return false ”

于 2012-10-16T16:10:09.563 回答
1

请记住将事件侦听器添加到您的图像中。

于 2012-06-28T18:10:55.820 回答