Hi,
this is to further explain this thread:
http://forums.coronalabs.com/topic/37529-swap-an-image/
How do I add a physics body during an event?
When a ball hits a brick the image is being remove (to be able to create a new image) and I want that new image to also have a body.
So in a “collision” event I run this:
if event.other.value == 2 then
print(“Value 2!”)
local j = event.other.j
local i = event.other.i
local x = event.other.x
local y = event.other.y
event.other:removeSelf()
event.other = nil
brickImageTable[j][i] = display.newImage(imageSheet, 4, x, y)
brickImageTable[j][i].value = 1
brickImageTable[j][i].name = “brick”
physics.addBody(brickImageTable[j][i], “static”, {density = 1, friction = 0, bounce = 0})
else
event.other:removeSelf()
event.other = nil
bricks.numChildren = bricks.numChildren - 1
end
But I get this error:
ERROR: physics.addBody() cannot be called when the world is locked and in the mi
ddle of number crunching, such as during a collision event.
Is it possible, someway, to create a physics body within an event?
Thanks in advance,
Best regards,
Tomas