Created
January 5, 2015 20:13
-
-
Save squarism/d99463dcec0216f88116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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