Hi all,
I was wondering if it would be possible to use one function on multiple objects in order to check x coordinates and then change them.
Thanks,
Chris
[import]uid: 126017 topic_id: 28163 reply_id: 328163[/import]
Hi all,
I was wondering if it would be possible to use one function on multiple objects in order to check x coordinates and then change them.
Thanks,
Chris
[import]uid: 126017 topic_id: 28163 reply_id: 328163[/import]
Yes. Do you want to check just one object at a time or be able to check a number of items at the same time? [import]uid: 74503 topic_id: 28163 reply_id: 113764[/import]
Hi,
Thanks for the response, and I would like to be able to check multiple objects at the same time.
Chris [import]uid: 126017 topic_id: 28163 reply_id: 113765[/import]
It’s perfectly possible. The best way to do it would be to add all the objects that you want to check into a table (or common display group) and use a loop to iterate through the table something like this:
[lua]-- Create table and add display objects
local tableOfObjects = {}
tableOfObjects[1] = display.newRect(0, 0, 150, 150)
tableOfObjects[1].x = 75
tableOfObjects[1].y = 200
tableOfObjects[2] = display.newRect(0, 0, 150, 150)
tableOfObjects[2].x = 150
tableOfObjects[2].y = 400
tableOfObjects[3] = display.newRect(0, 0, 150, 150)
tableOfObjects[3].x = 225
tableOfObjects[3].y = 600
– Function to iterate through them all in sequence
local function printAllX()
for i = 1, #tableOfObjects do
– Access the x property of all display objects in the table
– Simple print example here - add your own code to move the x positions
print( tableOfObjects[i].x )
end
end
printAllX()[/lua]
That should get you started. Of course, you could use a similar loop to set up the display objects too, but for simplicity in this example I haven’t.
[import]uid: 74503 topic_id: 28163 reply_id: 113767[/import]
Hey thank you very much this really helps. [import]uid: 126017 topic_id: 28163 reply_id: 113768[/import]
No problem. Glad to help. [import]uid: 74503 topic_id: 28163 reply_id: 113769[/import]