Moving Game Object in a loop on a timer (SOLVED)

Perfect. Thanks, everyone. All of these answers were super simple and easy to implement. Here’s what I ended up with:

function reload(self, dt)		

	local function right_done(self)
		anim.play_animation("idleRight")		
	end
	
	local function left_done(self)
		anim.play_animation("idleLeft")
	end
	
	local pos = go.get_position()
	
	if pos.x < 520 then
		go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, 520, go.EASING_LINEAR, 2, 0, right_done)
		anim.play_animation("walkRight")
	elseif pos.x > 440 then	
		go.animate(go.get_id(), "position.x", go.PLAYBACK_ONCE_FORWARD, 440, go.EASING_LINEAR, 2, 0, left_done)
		anim.play_animation("walkLeft")
	end	
end
1 Like