move object

hi
In my game. object move, right(x=1024) from left(x=0). i used timer call to function every 6ms and movement base on accelerometer right from left. it is working good, but i want call to function base on distance(ex - object appear on 1024 and move left when object less than 950 then call to function again and second object appear)

any help: [import]uid: 87661 topic_id: 27365 reply_id: 327365[/import]

You would be better off using a Runtime listener than a timer if the delay is only 6ms, although that’s by the by.

If you want to spawn a new object when your current one is at 1024 then you would use an if statement, eg;
[lua]if myObj.x >= 1024 then
–spawn function here
end[/lua] [import]uid: 52491 topic_id: 27365 reply_id: 111146[/import]

thanks@pellen

but as well as,i want maintain some distance between two every object.
[import]uid: 87661 topic_id: 27365 reply_id: 111182[/import]

Just change the 1024 to another value if you want more space and are spawning the new one at x=1024. Eg;

[lua]if myObj.x >= 700 then
–spawn function here
end[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 27365 reply_id: 111265[/import]