Hi again guys, having some trouble with onObjectTouch
function scene:createScene( event ) local screenGroup = self.view image = display.newImage("BGlvl.jpg", centerX, centerY) screenGroup:insert ( image ) object = display.newImage("btn1lvl.png") object:translate( 250, 200) object.id = "level1" screenGroup:insert ( object ) object = display.newImage("btn2lvl.png") object:translate( 400, 200) object.id = "level2" screenGroup:insert ( object ) object = display.newImage("btn3lvl.png") object:translate( 550, 200) object.id = "level3" screenGroup:insert ( object )
I have that in the createScene function.
And I’m calling the objects from the enterScene function like this :
function scene:enterScene( event ) local function onObjectTouch( event ) local level1 = event.target.id if event.phase == "began" then storyboard.gotoScene( "level1", "fade", 400) return true end end object:addEventListener( "touch", onObjectTouch ) print( "1: enterScene event" ) -- remove previous scene's view storyboard.purgeScene( "start" ) end
I’ve only made one touch listener, just for trying out.
Everything works OK, but when I’m in the level selection screen in the SIM.
If I try to press the image 1 to go to level1.lua, nothing happens.
If I press image 15 to go to level15.lua it works.
Do you guys have any idea what it could be ?
storyboard.gotoScene( "level1", "fade", 400 )
It doesn’t matter what I put in “level” if I put level1 or level 6, it’s still only allowing me to press the “level15button” to go to the next screen.