Class: Tatty::Anim
- Inherits:
-
Object
- Object
- Tatty::Anim
- Defined in:
- lib/tatty/anim.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#loop ⇒ Object
readonly
Returns the value of attribute loop.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #display ⇒ Object
-
#initialize(atlas, width:, height:, **kargs) ⇒ Anim
constructor
A new instance of Anim.
- #next ⇒ Object
- #reset ⇒ Object
- #step ⇒ Object
Constructor Details
#initialize(atlas, width:, height:, **kargs) ⇒ Anim
Returns a new instance of Anim.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tatty/anim.rb', line 9 def initialize(atlas, width:, height:, **kargs) @atlas = atlas @rate = kargs[:speed] || 2 @loop = kargs[:loop] || false if kargs[:loop_for].nil? @loop_for = -1 else @loop = false @loop_for_start = kargs[:loop_for] || -1 @loop_for = @loop_for_start end @name = kargs[:name] @width = width @height = height reset end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'lib/tatty/anim.rb', line 3 def height @height end |
#loop ⇒ Object (readonly)
Returns the value of attribute loop.
3 4 5 |
# File 'lib/tatty/anim.rb', line 3 def loop @loop end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/tatty/anim.rb', line 3 def name @name end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
3 4 5 |
# File 'lib/tatty/anim.rb', line 3 def rate @rate end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
3 4 5 |
# File 'lib/tatty/anim.rb', line 3 def width @width end |
Class Method Details
Instance Method Details
#display ⇒ Object
42 43 44 |
# File 'lib/tatty/anim.rb', line 42 def display @atlas[rate_frame] end |
#next ⇒ Object
46 47 48 49 |
# File 'lib/tatty/anim.rb', line 46 def next step display end |
#reset ⇒ Object
26 27 28 29 |
# File 'lib/tatty/anim.rb', line 26 def reset @frame = 0 @loop_for = @loop_for_start if @loop_for == 0 end |
#step ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tatty/anim.rb', line 31 def step @frame += 1 if rate_frame >= @atlas.count reset if self.loop @loop_for -= 1 if @loop_for > 0 true else false end end |