Hello to everybody, I’m new to Corona so I’m sorry for my simple questions. I’ve created a page for an interactive book where I added the code from the example “TimeAnimation”, it’s a ball that can be dragged and collides with screen borders, very simple, everything works fine.
Now I want to add a sound every time the ball collides. I modified the “onMoveCircle” function adding an audio.play for every condition, it works and sounds are played, but they are emitted also when the ball is not moving and it’s still on the ground. How can I set the audio.play so that it works only when the ball is moving ? Here is the code, anyone can help me ? Thank you
[lua]function onMoveCircle(event)
local timePassed = event.time - lastTime
lastTime = lastTime + timePassed
speedY = speedY + gravity
ball.x = ball.x + speedX*timePassed
ball.y = ball.y + speedY*timePassed
if ball.x >= screenW - ball.width*.5 then
ball.x = screenW - ball.width*.5
speedX = speedX*friction
speedX = speedX*-1 --change direction
audio.play( pop, {channel=myChannel} )
elseif ball.x <= ball.width*.5 then
ball.x = ball.width*.5
speedX = speedX*friction
speedX = speedX*-1 --change direction
audio.play( pop, {channel=myChannel} )
elseif ball.y >= screenH - ball.height*.5 then
ball.y = screenH - ball.height*.5
speedY = speedY*friction
speedX = speedX*friction
speedY = speedY*-1 --change direction
audio.play( pop, {channel=myChannel} )
elseif ball.y <= ball.height*.5 then
ball.y = ball.height*.5
speedY = speedY*friction
speedY = speedY*-1 --change direction
audio.play( pop, {channel=myChannel} )
end
end[/lua]
[import]uid: 106680 topic_id: 19303 reply_id: 319303[/import]
[import]uid: 52491 topic_id: 19303 reply_id: 74492[/import]