Hi,
This has been somewhat difficult for me to get my head around for a few days and I keep putting it off but now is the time I need to address it.
-
I have ship controlled by a joystick which is updated using enterframe.
-
when the ship reaches 80px the thrust sprite is played, this is attache to the ship using enterframe not a weld joint
-
the ship can also reverse meaning 80px becomes 440px so after440px thrust will play and below it will not.
-
everything working fine
Now my issue I need to play a sound when the ship hits 80px (the thrust sound) and below 80px it stops the sound, problem is it gets called 60 times because of the enterframe listener.
I tried using a flag / functions outside the listener and all manner of things but it just isnt happening.
I know I could use and invisible collision area to trigger the sound but I have a listener already so want to do it without.
below is the piece of code with comments of what i need to achieve:
function update () if player.x \> 80 and switchRotation == 0 then playerThrust.isVisible = true -----------------------switch thrust sound on --------------------- elseif player.x \< 80 and switchRotation == 0 then playerThrust.isVisible = false ----------------------switch thrust sound off---------------------- end if player.x \> 440 and switchRotation == 1 then playerThrust.isVisible = false -----------------------switch thrust sound off--------------------- elseif player.x \< 440 and switchRotation == 1 then playerThrust.isVisible = true -----------------------switch thrust sound on --------------------- end end Runtime:addEventListener("enterFrame", update)