Class: Stagecraft::Animation::Action
- Inherits:
-
Object
- Object
- Stagecraft::Animation::Action
- Defined in:
- lib/stagecraft/animation/action.rb
Constant Summary collapse
- LOOPS =
%i[repeat once ping_pong].freeze
Instance Attribute Summary collapse
-
#clamp_when_finished ⇒ Object
Returns the value of attribute clamp_when_finished.
-
#clip ⇒ Object
readonly
Returns the value of attribute clip.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#loop ⇒ Object
readonly
Returns the value of attribute loop.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#time_scale ⇒ Object
Returns the value of attribute time_scale.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #advance(dt) ⇒ Object
-
#initialize(clip, loop: :repeat, fade_in: 0.0) ⇒ Action
constructor
A new instance of Action.
- #stop ⇒ Object
Constructor Details
#initialize(clip, loop: :repeat, fade_in: 0.0) ⇒ Action
Returns a new instance of Action.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stagecraft/animation/action.rb', line 11 def initialize(clip, loop: :repeat, fade_in: 0.0) @clip = clip @loop = loop.to_sym raise ArgumentError, "invalid animation loop #{loop.inspect}" unless LOOPS.include?(@loop) @time = 0.0 @weight = fade_in.to_f.positive? ? 0.0 : 1.0 @fade_duration = [Float(fade_in), 0.0].max @fade_elapsed = 0.0 @time_scale = 1.0 @enabled = true @clamp_when_finished = true @ping_pong_phase = 0.0 end |
Instance Attribute Details
#clamp_when_finished ⇒ Object
Returns the value of attribute clamp_when_finished.
9 10 11 |
# File 'lib/stagecraft/animation/action.rb', line 9 def clamp_when_finished @clamp_when_finished end |
#clip ⇒ Object (readonly)
Returns the value of attribute clip.
8 9 10 |
# File 'lib/stagecraft/animation/action.rb', line 8 def clip @clip end |
#enabled ⇒ Object
Returns the value of attribute enabled.
9 10 11 |
# File 'lib/stagecraft/animation/action.rb', line 9 def enabled @enabled end |
#loop ⇒ Object (readonly)
Returns the value of attribute loop.
8 9 10 |
# File 'lib/stagecraft/animation/action.rb', line 8 def loop @loop end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
8 9 10 |
# File 'lib/stagecraft/animation/action.rb', line 8 def time @time end |
#time_scale ⇒ Object
Returns the value of attribute time_scale.
9 10 11 |
# File 'lib/stagecraft/animation/action.rb', line 9 def time_scale @time_scale end |
#weight ⇒ Object
Returns the value of attribute weight.
9 10 11 |
# File 'lib/stagecraft/animation/action.rb', line 9 def weight @weight end |
Instance Method Details
#advance(dt) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/stagecraft/animation/action.rb', line 26 def advance(dt) return time unless enabled elapsed = Float(dt) update_fade(elapsed) duration = clip.duration return @time = 0.0 if duration.zero? delta = elapsed * time_scale return advance_ping_pong(delta, duration) if loop == :ping_pong @time += delta apply_loop(duration) time end |
#stop ⇒ Object
42 43 44 45 |
# File 'lib/stagecraft/animation/action.rb', line 42 def stop @enabled = false self end |