Rectangle that will move left-right transition

Can someone help me with this? I want to make object (rectangle) from center to left-right then back to left and so on. I hope someone will understand me.

Thanks  :slight_smile:

you mean you want to move the rectangle in a ping-pong fashion?

This code will do that (may have typos)

local cx = display.contentCenterX local cy = display.contentCenterY local left = cx - display.actualContentWidth/2 local right = cx + display.actualContentWidth/2 local isFirst = true local time = 4000 local rect = display.newRect( cx, cy, 100, 40 ) local ping local pong ping = function( self ) local t = (isFirst) and time/2 or time isFirst = false self.onComplete = pong transition.to( self, { x = left + 50, time = t, onComplete = self } end pong = function( self ) self.onComplete = ping transition.to( self, { x = right - 50, time = time, onComplete = self } end

I also have a path following example here:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/08/paths

https://www.youtube.com/watch?v=QyaMWEo3-9E&feature=youtu.be

you mean you want to move the rectangle in a ping-pong fashion?

This code will do that (may have typos)

local cx = display.contentCenterX local cy = display.contentCenterY local left = cx - display.actualContentWidth/2 local right = cx + display.actualContentWidth/2 local isFirst = true local time = 4000 local rect = display.newRect( cx, cy, 100, 40 ) local ping local pong ping = function( self ) local t = (isFirst) and time/2 or time isFirst = false self.onComplete = pong transition.to( self, { x = left + 50, time = t, onComplete = self } end pong = function( self ) self.onComplete = ping transition.to( self, { x = right - 50, time = time, onComplete = self } end

I also have a path following example here:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/08/paths

https://www.youtube.com/watch?v=QyaMWEo3-9E&feature=youtu.be