Hi,
I’m trying to build a simple snowball game. Two guys, one snowball. When the snowball hits the opposite guy or the floor, it should disappear and re-appear in the hand of the throwing guy.
Sounds simple. But I’m having problems with re-initializing the snowball after it hit the bottom or the other guy. My code looks like this:
.....
......
local floor = ........
physics.start()
physics.setGravity(0, 0)
physics.setDrawMode( "normal" )
local snowball = display.newImage("snowball.png")
snowball.x = 50
snowball.y = display.stageHeight - 60
physics.addBody( snowball, { density=0.3, friction=0.3, bounce=0.1, radius=20 } )
snowball:addEventListener( "touch", dragBody )
local function dragBody( event )
physics.setGravity(0, 10)
gameUI.dragBody( event, { maxForce=55, frequency=5, dampingRatio=10} )
end
local function onCollision( event )
if event.object1 == floor then
if ( event.phase == "began" ) then
local oldsnowball = event.object2
oldsnowball:removeSelf()
local snowball = display.newImage("snowball.png")
snowball.x = 50
snowball.y = display.stageHeight - 60
snowball:addEventListener( "touch", dragBody )
end
end
end
The problem is: the new snowball appears but as soon as I try to drag it, the whole Corona Simulator crashes. So I can only drag the first snowball. If I try to re-add the new snowball to the physics with physics.addBody in onCollision(), the game crashes as well.
Do you guys have any hints what I’m doing wrong? [import]uid: 11219 topic_id: 3616 reply_id: 303616[/import]