I just can’t seem to find the right combination of code to do what I want.
Simple really, when a collision occurs on my “ball” I want to stop everything, move the ball into a “winning position” I declare on top of code (x,y) and then show an alert event and play a sound.
But what happens is when the ball hits the winning spot it will sometimes show multiple alerts and play the winning chime more than once.
I have a simple listener event for a collision on the winning spot.
I’ve tried several different methods but below is my code, maybe someone can help me?
[lua]–Ending a level
local function endlevel( event )
if event.other.name == “myball” then --If it’s the ball then
ball:setLinearVelocity(0, 0)
ball.angularVelocity = 0
win:removeEventListener(“collision”, endlevel)
ball:removeEventListener(“collision”, ballsoundevent)
ball.linearDamping = windampening --Give it some dampening
ball:applyForce( ballforce, ballforce, 10, 15 ) --Spin it a little
transition.to( ball, { time=100, x=winnerxspot+5, y=winneryspot+6 } ) --Move it to the exact center of winning spot
local alert = native.showAlert( “You won”, “Good job.”, { “Next Level”, “Play again” }, onlevelComplete ) --Alert box
audio.play(winsound) --Play sound
end
end
[/lua] [import]uid: 9046 topic_id: 7144 reply_id: 307144[/import]