object:translate vs object.x,object.y

This is a question for the Corona staff. I’ve read on your tutorials that the object:translate(dx,dy) method is more efficient than assigning new x,y coordinates.

May I know how much more efficient is the translate method? Because right now I’m just using the translate method by replacing the usual
[lua]object.x,object.y = newX,newY[/lua]

with

[lua]object:translate(newX-object.x,newY-object.y)[/lua]

And in what way is the translate more efficient? Memory usage? Timings? [import]uid: 108204 topic_id: 27876 reply_id: 327876[/import]

Hey there - I had to consult with a colleague to get a solid answer on this so I apologize for the late reply. Here’s what he had to say;

“To answer the question, the translate API is more efficient in timing because you are only referencing and setting the parameters once instead of twice. I don’t have any performance data but the user could measure the difference by creating one loop that calls translate and one that sets the .x and .y parameters and measure the elapsed time for each.”

I hope that’s helpful :slight_smile:

Peach [import]uid: 52491 topic_id: 27876 reply_id: 113146[/import]