Problem changing scene with touch button

Hi!
I have a sub-menu where you can change settings before you start playing the game. If you want to change the level and close the sub-menu you press onCloseTouch(). And if you want to start the game you press onPlayTouch(). The problem is that if you press onCloseTouch() and go back to the start-menu, then go back to the same sub-menu the onPlayTouch() doesn’t work. You can click on the button, btnPlay, and you hear the tapSound and it changes picture, but it doesn’t change scene to loadlevel1. And I have no idea why it is like that. Also, for some reason, you can only click on the right side of the btnPlay (like 30px) to get an action, not on the other side! And it’s the same for btnClose; but on btnClose you can only click on the left side of the button (like 30px) to get an action.

Does someone have an idea what I’m doing wrong?

Best regards,
joelwe

[code]
–***************************************************

– onPlayTouch() Changes scene to level 1

–***************************************************

local onPlayTouch = function( event )
if event.phase == “release” then
audio.play( tapSound )
saveChanges()

director:changeScene( “loadlevel1” )
end
end

–Show play-button
local btnPlay = ui.newButton{
defaultSrc = “images/bg/menu_bg_lost_jug.png”,
defaultX = 122,
defaultY = 39,
overSrc = “images/bg/menu_bg_lost_jug_over.png”,
overX = 122,
overY = 39,
onEvent = onPlayTouch,
id = “BtnPlay”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}

btnPlay.x = 370
btnPlay.y = 270
btnPlay.isVisible = false

menuGroup:insert( btnPlay )
timer.performWithDelay( 200, function() btnPlay.isVisible = true; end, 1 )

–***************************************************

– onCloseTouch() Closes number 3 settings

–***************************************************

local btnClose

local onCloseTouch = function( event )
if event.phase == “release” then

audio.play( tapSound )

bgSettings:removeSelf(); bgSettings = nil
–bgBall1:removeSelf(); bgBall1 = nil
–bgBall2:removeSelf(); bgBall2 = nil
–bgBall3:removeSelf(); bgBall3 = nil
txtBall:removeSelf(); txtBall = nil
txtBall2:removeSelf(); txtBall2 = nil
txtHand:removeSelf(); txtHand = nil
txtHand2:removeSelf(); txtHand2 = nil
–txtBall3:removeSelf(); txtBall3 = nil
btnPlay:removeSelf(); btnPlay = nil
txtSettings:removeSelf(); txtSettings = nil
ball1Selector:removeSelf(); ball1Selector = nil
ball2Selector:removeSelf(); ball2Selector = nil
ball3Selector:removeSelf(); ball3Selector = nil
handSelector:removeSelf(); handSelector = nil
shadeRect:removeSelf(); shadeRect = nil
btnClose:removeSelf(); btnClose = nil

isLevelSelection = false
number3.isActive = false
–ofBtn.isActive = true
end
end

–Show close-button
btnClose = ui.newButton{
defaultSrc = “images/bg/menu_bg_lost_menu.png”,
defaultX = 122,
defaultY = 39,
overSrc = “images/bg/menu_bg_lost_menu_over.png”,
overX = 122,
overY = 39,
onEvent = onCloseTouch,
id = “CloseButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}

btnClose.x = 110;
btnClose.y = 270
btnClose.isVisible = false

menuGroup:insert( btnClose )
timer.performWithDelay( 201, function() btnClose.isVisible = true; end, 1 )
[/code] [import]uid: 54640 topic_id: 21919 reply_id: 321919[/import]

Try changing onEvent to onPress or onRelease - right now it would call the function twice, once when pressed and once when released, which may be contributing.

The other thing to check if hearing sounds correctly is if it is changing but you can’t see it - in your level1.lua file do a print statement, print “level 1” or the like - see if it prints when you hear the sound play.

If it does this is likely an issue with no adding to groups or cleaning them up properly.

Peach :slight_smile: [import]uid: 52491 topic_id: 21919 reply_id: 87250[/import]

Hi Peach!
It seems to work with

onPress = onPlayTouch

and

local onPlayTouch = function( press ) 

Thanks! :smiley: [import]uid: 54640 topic_id: 21919 reply_id: 87265[/import]

No worries, happy to hear it’s working for you now :slight_smile: [import]uid: 52491 topic_id: 21919 reply_id: 87418[/import]