Hi,
I’m doing a Breakout clone and when it hits one of the dark-grey bricks I want the brick to still be alive (i.e. not be remove, still have it’s body etc.) but only change color (i.e. picture) from one picture to another but I can’t seem to get it to work.
Here is a for loop generating all the bricks and it works fine:
local brick = display.newImage(findBrick(brickTable[j][i]))
brick.x = (i * brickWidth) - brickWidth - 22
brick.y = j * brickHeight - 6
brick.name = “brick”
brick.value = brickTable[j][i]
brick.i = i
brick.j = j
– Create physic body for each brick
physics.addBody(brick, “static”, {density = 1, friction = 0, bounce = 0})
– Add each brick to display group
bricks.insert(bricks, brick)
The problem is during the collision event, the dark-grey bricks have value 11:
if event.other.value == 11 then
local i = event.other.i
local j = event.other.j
– event.other:removeSelf()
– event.other = nil
local brick = display.newImage(“10.png”)
brick.x = (i * brickWidth) - brickWidth - 22
brick.y = j * brickHeight - 6
brick.name = “brick”
brick.value = 10
brick.i = i
brick.j = j
– Create physic body for each brick
--physics.addBody(brick, “static”, {density = 1, friction = 0, bounce = 0})
– Add each brick to table
bricks.insert(bricks, brick)
else
event.other:removeSelf()
event.other = nil
bricks.numChildren = bricks.numChildren - 1
end
Must I remove the previous picture or can I just overwrite the current image and keep all the remaing values?
Thanks in advance!
Best regards,
Tomas