Skip to content

Instantly share code, notes, and snippets.

@squarism
Created January 5, 2015 20:13
Show Gist options
  • Save squarism/d99463dcec0216f88116 to your computer and use it in GitHub Desktop.
Save squarism/d99463dcec0216f88116 to your computer and use it in GitHub Desktop.
define_behavior :sliding do
requires :director
setup do
actor.has_attribute :x_tween
actor.has_attribute :y_tween
actor.has_attributes tween_time: opts[:time]
director.when :update do |time|
if actor.x_tween
if !actor.x_tween.done
update_position time
else
actor.x_tween = nil
actor.y_tween = nil
end
end
end
actor.when :slide, &method(:slide)
end
helpers do
def update_position(time)
actor.x_tween.update time
actor.y_tween.update time
actor.x = actor.x_tween.value
actor.y = actor.y_tween.value
end
def slide(x:, y:, time: actor.tween_time, style: Tween::Sine::InOut)
actor.x_tween = Tween.new(actor.x, x, style, time)
actor.y_tween = Tween.new(actor.y, y, style, time)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment