I’m developing a Pong game, just to learn Solard2D.
When the ball touches an invisible segment all over the right or left edge of the screen then I have a point.
So on ball collision OnEvent I have the choice whether or not I have reached the required score, in this case I stop the physical world, the ball, and close the game.
I read that in on event I can’t close the physical world so I set a timer.
The problem is, in any case, I can’t stop the world. Where am I wrong?
Here are the pieces of code:
local function onCollision( self, event )
if ( event.phase == "began" ) then
if (self.Name == "ball") and (event.other.Name == "edgeDx" ) then
if settingsTable["sound"] == true then audio.play(pointSnd) end
writeScreenPoint()
timer.performWithDelay( 25, stopBall, 1 )
timer.performWithDelay( 30, centerBall, 1 )
if someOneWins() == true then
-- someone wins, I go on starting game screen
composer.gotoScene( "welcome", { time=100, effect="crossFade" } )
end
end
return true
end
function scene:hide( event )
local phase = event.phase
if ( phase == "will" ) then
transition:pause()
physics.pause()
Runtime:removeEventListener(...) -- remove all EventListener
local result = function() return physicsStop( physics.stop() ) end
repeat
timer.performWithDelay( 25, result)
print("Waiting physics stops...")
until result == true
…
will never stops an loops forever.
Thanks!
Renato