How to Reuse objects

if I do

a = display.newCircle(x,y,r)
b = a
b.x = x1

then I am also doing

a.x = x1

and then a and b are in the same position

how can I change b.x without changing a.x at the same time?

I want to have lots of circles in different positions without having to do

display.newCircle()

for each one.

Note that the "circle"is only an example, I want to know this and apply it to a more complicated objects that I want to generate using rectangles and circles.

Thanks for any help on this

You are only creating one single object there so naturally when you change b.x you will be changing the position of it. You will want to create more than one circle object, or whatever your final object will be.

To do this you will most likely want to use tables and a loop, something like this:

1
2
3
4
5
6
7
8
local objects = {}
 
for i = 1, 20, 1 do
     objects[i] = display.newCircle(0, 0, 20)
end
 
objects[5].x = 50
objects[7].x = 20

Thanks Graham

No problem.

views:1131 update:2011/10/3 8:06:12
corona forums © 2003-2011