How to respawn in table array?

Hi folks,

I guess this is an easy one - but I haven’t figured out to do this…

I am having all my images in an array (table) called bricks. I have built up my dummy game with regular rectangles, but I am now changing those to images that looks more nicer. I am almost done, but how should I respawn the following object “bricks[j]” with an image, and with correct x,y axis?

  
if(oldColor==1 and color==3) then  
 --\> old code to access the object and change fill color  
 bricks[j]:setFillColor(255,255,0)  
  
end  
  

Best regards, Joakim [import]uid: 81188 topic_id: 16388 reply_id: 316388[/import]

OK, some more code…

This is the spawn function

function spawn(x,y,myx,myy)  
 local brick = display.newImageRect( "b\_lightblue.png", 128,128)  
 brick.x = x  
 brick.y = y  
 brick.myX = myx  
 brick.myY = myy  
 brick.index = #bricks + 1  
 Scene:insert(1,brick)  
 bricks[brick.index] = brick  
  
 return object  
end  

and this is my latest effort to solve the change and it is within a loop:

bricks[j] = display.newImageRect("b\_yellow.png",128,128)  
bricks[j].x = bricks[j].x  
bricks[j].y = bricks[j].y   
bricks[j].myX = bricks[j].myX  
bricks[j].myY = bricks[j].myY  

Problem is that the new object is displayed, but I cant get it into the correct x,y? [import]uid: 81188 topic_id: 16388 reply_id: 61161[/import]

Solved, I removed the previous respawned object, and readded it. Sometimes things are easier then you are aware of :slight_smile:

Joakim [import]uid: 81188 topic_id: 16388 reply_id: 61279[/import]