Created
March 20, 2014 16:45
-
-
Save 2tunnels/9668318 to your computer and use it in GitHub Desktop.
Corona SDK physics.removeBody() cannot be called ... during collision event.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local storyboard = require( "storyboard" ) | |
local physics = require( "physics" ) | |
local scene = storyboard.newScene( "game" ) | |
local box | |
local ground | |
function scene:createScene( event ) | |
local group = self.view | |
box = display.newRect( 0, 0, 200, 200 ) | |
box.x = display.contentCenterX | |
box.y = display.contentCenterY | |
box:setFillColor( 0, 1, 0 ) | |
group:insert( box ) | |
ground = display.newRect( 0, 0, 600, 100 ) | |
ground.x = display.contentCenterX | |
ground.y = display.contentCenterY + 600 | |
ground:setFillColor( 1, 0, 0 ) | |
group:insert( ground ) | |
end | |
function scene:enterScene( event ) | |
local group = self.view | |
physics.start() | |
physics.addBody( box, "dynamic", { density = 1, friction = 1, bounce = 0.5 } ) | |
physics.addBody( ground, "static", { density = 1, friction = 1, bounce = 0.5 } ) | |
box.collided = false | |
function box:collision( event ) | |
if not box.collided then | |
box.collided = true | |
storyboard.gotoScene( "start" ) | |
end | |
return true | |
end | |
box:addEventListener( "collision", box ) | |
end | |
function scene:exitScene( event ) | |
local group = self.view | |
physics.pause() | |
physics.removeBody( box ) | |
physics.removeBody( ground ) | |
box:removeEventListener( "collision", box ) | |
end | |
function scene:destroyScene( event ) | |
local group = self.view | |
end | |
scene:addEventListener( "createScene", scene ) | |
scene:addEventListener( "enterScene", scene ) | |
scene:addEventListener( "exitScene", scene ) | |
scene:addEventListener( "destroyScene", scene ) | |
return scene |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local storyboard = require( "storyboard" ) | |
storyboard.gotoScene( "start" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local storyboard = require( "storyboard" ) | |
local scene = storyboard.newScene( "start" ) | |
local button | |
function scene:createScene( event ) | |
local group = self.view | |
button = display.newRect( 0, 0, 400, 100 ) | |
button.x = display.contentCenterX | |
button.y = display.contentCenterY | |
group:insert( button ) | |
end | |
function scene:enterScene( event ) | |
local group = self.view | |
function button:touch( event ) | |
if event.phase == "ended" then | |
storyboard.gotoScene( "game" ) | |
end | |
return true | |
end | |
button:addEventListener( "touch", button ) | |
end | |
function scene:exitScene( event ) | |
local group = self.view | |
button:removeEventListener( "touch", button ) | |
end | |
function scene:destroyScene( event ) | |
local group = self.view | |
end | |
scene:addEventListener( "createScene", scene ) | |
scene:addEventListener( "enterScene", scene ) | |
scene:addEventListener( "exitScene", scene ) | |
scene:addEventListener( "destroyScene", scene ) | |
return scene |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment