Class: Okami::Sprite
- Inherits:
-
Object
- Object
- Okami::Sprite
- Defined in:
- lib/okami/sprite.rb
Constant Summary collapse
- @@modes =
{ loop: {direction: :forward, update_method: :update_loop}, backward_loop: {direction: :backward, update_method: :update_backward_loop}, reverse_loop: {direction: :backward, update_method: :update_backward_loop}, forward: {direction: :forward, update_method: :update_forward}, backward: {direction: :backward, update_method: :update_backward}, reverse: {direction: :backward, update_method: :update_backward}, ping_pong: {direction: :_forward, update_method: :update_ping_pong} }
Instance Attribute Summary collapse
-
#frame_index ⇒ Object
Returns the value of attribute frame_index.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#last_frame_index ⇒ Object
readonly
Returns the value of attribute last_frame_index.
-
#mode ⇒ Object
Returns the value of attribute mode.
Class Method Summary collapse
Instance Method Summary collapse
- #draw(*args) ⇒ Object
- #draw_rot(*args) ⇒ Object
- #draw_using(image_attributes) ⇒ Object
- #finished? ⇒ Boolean (also: #animation_finished?)
- #fps ⇒ Object
- #fps=(fps) ⇒ Object
-
#initialize(options) ⇒ Sprite
constructor
A new instance of Sprite.
- #random_frame_index ⇒ Object
- #update(dt = @@default_dt) ⇒ Object
Constructor Details
#initialize(options) ⇒ Sprite
Returns a new instance of Sprite.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/okami/sprite.rb', line 15 def initialize raise_possible_errors self.images = [:images] self.fps = [:fps] self.frame_index = [:frame_index] if [:frame_index] self.mode = [:mode] || :loop set_initial_frame_index update_current_image @@default_dt ||= $window.update_interval / 1000.0 end |
Instance Attribute Details
#frame_index ⇒ Object
Returns the value of attribute frame_index.
64 65 66 |
# File 'lib/okami/sprite.rb', line 64 def frame_index @frame_index end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
2 3 4 |
# File 'lib/okami/sprite.rb', line 2 def image @image end |
#images ⇒ Object
Returns the value of attribute images.
2 3 4 |
# File 'lib/okami/sprite.rb', line 2 def images @images end |
#last_frame_index ⇒ Object (readonly)
Returns the value of attribute last_frame_index.
2 3 4 |
# File 'lib/okami/sprite.rb', line 2 def last_frame_index @last_frame_index end |
#mode ⇒ Object
Returns the value of attribute mode.
55 56 57 |
# File 'lib/okami/sprite.rb', line 55 def mode @mode end |
Class Method Details
.modes ⇒ Object
13 |
# File 'lib/okami/sprite.rb', line 13 def self.modes; @@modes end |
Instance Method Details
#draw(*args) ⇒ Object
29 |
# File 'lib/okami/sprite.rb', line 29 def draw *args; @image.draw *args end |
#draw_rot(*args) ⇒ Object
30 |
# File 'lib/okami/sprite.rb', line 30 def draw_rot *args; @image.draw_rot *args end |
#draw_using(image_attributes) ⇒ Object
31 |
# File 'lib/okami/sprite.rb', line 31 def draw_using image_attributes; @image.draw_using image_attributes end |
#finished? ⇒ Boolean Also known as: animation_finished?
47 48 49 50 51 52 |
# File 'lib/okami/sprite.rb', line 47 def finished? case @mode when :forward; @frame_index == @last_frame_index when :backward; @frame_index == 0 end end |
#fps ⇒ Object
33 |
# File 'lib/okami/sprite.rb', line 33 def fps; @delta_frame_index * 60.0 end |
#fps=(fps) ⇒ Object
34 |
# File 'lib/okami/sprite.rb', line 34 def fps=fps; @delta_frame_index = fps / 60.0 end |
#random_frame_index ⇒ Object
72 73 74 |
# File 'lib/okami/sprite.rb', line 72 def random_frame_index rand * @images.length end |
#update(dt = @@default_dt) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/okami/sprite.rb', line 36 def update dt=@@default_dt case @direction when :forward then @frame_index += @delta_frame_index * dt * 60.0 when :backward then @frame_index -= @delta_frame_index * dt * 60.0 end @update_method.call update_current_image end |