Class: Chingu::AsyncTasks::Tween
- Inherits:
-
Chingu::Async::BasicTask
- Object
- Chingu::Async::BasicTask
- Chingu::AsyncTasks::Tween
- Defined in:
- lib/chingu/async_tasks/tween.rb
Overview
Basic tweening for numerical properties.
game_object.async.tween 1000, :property => new_value
Direct Known Subclasses
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(duration, properties) ⇒ Tween
constructor
TODO Tweening is pretty dumb…make it smarter.
- #update(object) ⇒ Object
Constructor Details
#initialize(duration, properties) ⇒ Tween
TODO Tweening is pretty dumb…make it smarter.
34 35 36 37 38 39 |
# File 'lib/chingu/async_tasks/tween.rb', line 34 def initialize(duration, properties) super() @have_initial_values = false @age, @life = 0, duration @properties = properties end |
Instance Method Details
#finished? ⇒ Boolean
52 53 54 |
# File 'lib/chingu/async_tasks/tween.rb', line 52 def finished? @age >= @life end |
#update(object) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/chingu/async_tasks/tween.rb', line 41 def update(object) set_initial_values(object) unless have_initial_values? @age += $window.milliseconds_since_last_tick t = @age.to_f / @life t = 1.0 if t > 1 @properties.each do |name, range| object.send "#{name}=", range.interpolate(t) end end |