Moving object to the right and then to the left

Hi everyone
I am trying to create some simple examples of item that most of games contains.
Now i am trying to do that:
i have a object and i need to move it to the right and then to the left, and then to the right… it will be a loop. i am using transitions with some variables, and running inside of a runtime, but i am having some problems, someone has already created something similar? or have some ideas to how to build that?

Thanks [import]uid: 26056 topic_id: 22755 reply_id: 322755[/import]

Hi Blickon

I dont know if there a better way, but I do this…
You have to create a function, lets say “animate”, this function will ask for the boundaries x and y positions and then changes the orientation of the object (basically adding 1 to move to the right adding -1 to move to the left)

Here is my example

local increment =1 – Add 1 to x coordinate, to move right, Add -1 to x coordinate to move left
local xbound_right = 300 – The maximun value for x coordinate at right
local xbound_left = 200 – The minimum value for x coordinate at left

function animate (event)
if object.x > xbound_right then
increment = -1
end

if object.x < xbound_left then
increment = 1
end

object.x = object.x + increment
end

– Now add a listener to update the animation
Runtime:addEventListener( “enterFrame”, animate );

This code will move the “object” between 200 and 300 coordinates. Maybe there another ways to do it, but this works for me.

Good Luck.

Best Regards!!!
Jose [import]uid: 84893 topic_id: 22755 reply_id: 90869[/import]

Hi jose. it is great and works fine to me
Thank you very much for the help :slight_smile: [import]uid: 26056 topic_id: 22755 reply_id: 90977[/import]