-- main.lua local storyboard = require "storyboard" local function main() storyboard.gotoScene( "scene1" ) end main()
-- scene1.lua local storyboard = require "storyboard" local scene = storyboard.newScene() storyboard.purgeOnSceneChange = true local function onTap( event ) print( "GOING TO SCENE 2!!!" ) local option = { isModal = true } storyboard.showOverlay( "scene2", option ) return true end function scene:createScene( event ) Runtime:addEventListener( "tap", onTap ) end function scene:destroyScene( event ) Runtime:removeEventListener( "tap", onTap ) end scene:addEventListener( "createScene" ) scene:addEventListener( "destroyScene" ) return scene
-- scene2.lua local storyboard = require "storyboard" local scene = storyboard.newScene() storyboard.purgeOnSceneChange = true local function onTap( event ) print( "CLOSING SCENE 2!!!" ) storyboard.hideOverlay() return true end function scene:createScene( event ) Runtime:addEventListener( "tap", onTap ) end function scene:destroyScene( event ) Runtime:removeEventListener( "tap", onTap ) end scene:addEventListener( "createScene" ) scene:addEventListener( "destroyScene" ) return scene
When I tap at scene1, it will immediately close scene2 because scene2 detected the tap. Is there a way to prevent this from happening?
Since you are adding tap listeners to the entire screen, you should be doing the Runtime:addEventListener in the enterScene() function and the Runtime:removeEventListener() in the exitScene(). They are the only two functions guaranteed to get called every time.
Is there a reason you are putting tap handlers on the whole screen rather than putting it on a button or something?
The reason for doing that is just to simulate my problem I encounter. My pet runs around randomly in my iPhone, and when I tap my pet, it opens a menu. However, this is the problem, when I close the screen by tapping on a button (let’s say I put it on the bottom right corner of the screen) and if the pet runs there when I tap it, the menu will be opened again.
I will try to change it to enterScene and exitScene to see how it works
That is my current work around now (changing the detection to began or onPress). However I do not want that because when a player hold down a button before releasing, a text is popped up showing what it is.
EDIT:
Changing to enterScene works nicely. However I just notice it won’t work for my situation as my event listener is added when my pet is created. Hmmm… D:
Since you are adding tap listeners to the entire screen, you should be doing the Runtime:addEventListener in the enterScene() function and the Runtime:removeEventListener() in the exitScene(). They are the only two functions guaranteed to get called every time.
Is there a reason you are putting tap handlers on the whole screen rather than putting it on a button or something?
The reason for doing that is just to simulate my problem I encounter. My pet runs around randomly in my iPhone, and when I tap my pet, it opens a menu. However, this is the problem, when I close the screen by tapping on a button (let’s say I put it on the bottom right corner of the screen) and if the pet runs there when I tap it, the menu will be opened again.
I will try to change it to enterScene and exitScene to see how it works
That is my current work around now (changing the detection to began or onPress). However I do not want that because when a player hold down a button before releasing, a text is popped up showing what it is.
EDIT:
Changing to enterScene works nicely. However I just notice it won’t work for my situation as my event listener is added when my pet is created. Hmmm… D: