Search code examples
storyboardcoronasdkscene

StoryBoard API in Corona


I am trying to use StoryBoard API in Corona. However, my button touch event is not working at all. Can you look at my code and help me out?

main.lua :

     local storyboard = require "storyboard"

     storyboard.gotoScene( "scene1", "fade", 500 )

scene1:

     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

And my second scene is same like that. However when i touch on the image, it does not go to second scene.


Solution

  • Remember to add the event listener to your image.