Changing the look of an object, then making it go away (not working!)

I’m playing around with a Breakout-type game and dealing with bricks. I created an array (table?) of bricks across the top of the screen and when a brick is hit, that brick is deleted and a new brick is put in the same place (so you have to hit a brick multiple times, each time cracking it a little more).

When I do that with two clicks it works but when I try to make a brick break on 3 clicks I’m running into problems.

Here’s a 2.5 minute video that shows the problem:

http://instantvideowebpages.com/play/notmplvid.php?384

And this is the listener code as seen in the video:

[code]local hitBrick = function( event )
local t = event.target
local phase = event.phase

if “began” == phase then
local myIndex = t.myIndex
local x = t.x
local y = t.y
bricks[myIndex].bricknum = bricks[myIndex].bricknum + 1
if bricks[myIndex].bricknum > 2 then
playBeep()
bricks[myIndex]:removeSelf()
t:removeSelf() – destroy object
else
playTileHit()
BuildABrick(bricks[myIndex].bricknum, x, y, myIndex)
end
end
return true
end
[/code]

Thanks to anyone who can point me in the right direction.

Jay
[import]uid: 9440 topic_id: 2968 reply_id: 302968[/import]

Are you removing the first brick image before you place the “broken” brick image? [import]uid: 4454 topic_id: 2968 reply_id: 8515[/import]

Well, yes and no. I’m taking what’s in bricks[x] and putting the broken brick in – so while I’m not deleting the first brick, I’m overwriting it.

And going from Brick1 to Brick2 it works – after two clicks Brick2 vanishes.

But going from Brick1 to Brick2 to Brick3, after the last click Brick2 shows up. You can’t click on it any more, and Brick3 no longer shows, but the Brick2 image is sitting there.

Jay
[import]uid: 9440 topic_id: 2968 reply_id: 8517[/import]

In order to completely remove an image, you should removeSelf it. Overwriting its reference only deletes its table reference, so you could be winding up with an orphaned brick image. [import]uid: 4454 topic_id: 2968 reply_id: 8529[/import]