I have made a display group and inserted image objects into it using a for loop like this:
(there may be mistakes here, the code is just to get the point accross :unsure: )
for x = 1,4 do local object = display.newImage("object.png") object.x = math.random(20,100) object.y = math.random(20,100) object.isBodyActive = true physics.addBody(object, "static", {density = 1, friction = 0, bounce =0, radius = (object.contentWidth\*.33)}) objectGroup.insert(objectGroup,object) end
The objects in the objectGroup are not meant to move on screen, just detect collisions.
I have not set the objectGroup’s x and y
Later I loop through the objects in another for loop, and use their x and y positions in calculations.
for x = 1,4 do local deltaX = objectGroup[x].x - player.x local deltaY = objectGroup[x].y - player.y --- other stuff here end
So to my question, I am finding that some of my calculations are not repeatable because the objects for some reason are moving in the table.
for example in one call to the for loop the order is {obj1, obj2, obj3} and the next call to the for loop, the order ends up being something like {obj2, obj1, obj3}
So, to sum it up, why are the elements of the display group changing position? The only thing my code does with them is read the object’s properties.
Thanks for any help,
Pace