Class: Metro::Animation
- Inherits:
-
Object
- Object
- Metro::Animation
- Defined in:
- lib/metro/animation.rb
Overview
The animation is an wrapper object for an array of Gosu::Images that also contains the additional information on the path, height, width, and tileability.
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#images ⇒ Object
Returns the value of attribute images.
-
#path ⇒ Object
Returns the value of attribute path.
-
#tileable ⇒ Object
Returns the value of attribute tileable.
-
#time_per_image ⇒ Object
Returns the value of attribute time_per_image.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.create(options) ⇒ Object
Create an animation image given the window, path, width, height, and tileability.
-
.find_or_create(options) ⇒ Object
Finds an existing image or creates a new image given the window, path, width, height and tileablilty.
Instance Method Summary collapse
-
#age ⇒ Fixnum
The age of the animation.
-
#complete? ⇒ Boolean
The animation is complete if it the current index exceeds the number of images.
-
#current_image_index ⇒ Object
The current animation image to display.
-
#current_index ⇒ Object
The current animation image count.
-
#current_time ⇒ Fixnum
The current time in the game.
-
#image ⇒ Object
A Gosu::Image to be displayed in a animation sequence.
-
#initialize(params = {}) ⇒ Animation
constructor
A new instance of Animation.
-
#start_time ⇒ Fixnum
The game time when the animation started to display.
-
#to_hash ⇒ Object
A hash representation of the Animation.
Constructor Details
#initialize(params = {}) ⇒ Animation
Returns a new instance of Animation.
11 12 13 14 15 16 17 18 |
# File 'lib/metro/animation.rb', line 11 def initialize(params = {}) @images = Array(params[:images]) @path = params[:path] @height = params[:height] @width = params[:width] @tileable = params[:tileable] @time_per_image = params[:time_per_image] end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
9 10 11 |
# File 'lib/metro/animation.rb', line 9 def height @height end |
#images ⇒ Object
Returns the value of attribute images.
9 10 11 |
# File 'lib/metro/animation.rb', line 9 def images @images end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/metro/animation.rb', line 9 def path @path end |
#tileable ⇒ Object
Returns the value of attribute tileable.
9 10 11 |
# File 'lib/metro/animation.rb', line 9 def tileable @tileable end |
#time_per_image ⇒ Object
Returns the value of attribute time_per_image.
9 10 11 |
# File 'lib/metro/animation.rb', line 9 def time_per_image @time_per_image end |
#width ⇒ Object
Returns the value of attribute width.
9 10 11 |
# File 'lib/metro/animation.rb', line 9 def width @width end |
Class Method Details
.create(options) ⇒ Object
Create an animation image given the window, path, width, height,
and tileability.
104 105 106 |
# File 'lib/metro/animation.rb', line 104 def self.create() new .merge(images: create_gosu_images()) end |
.find_or_create(options) ⇒ Object
Finds an existing image or creates a new image given the window, path, width, height and tileablilty.
90 91 92 |
# File 'lib/metro/animation.rb', line 90 def self.find_or_create() new .merge(images: find_or_create_gosu_images()) end |
Instance Method Details
#age ⇒ Fixnum
Returns the age of the animation.
47 48 49 |
# File 'lib/metro/animation.rb', line 47 def age current_time - start_time end |
#complete? ⇒ Boolean
Returns the animation is complete if it the current index exceeds the number of images.
69 70 71 |
# File 'lib/metro/animation.rb', line 69 def complete? current_index > (images.size - 1) end |
#current_image_index ⇒ Object
Returns the current animation image to display.
61 62 63 |
# File 'lib/metro/animation.rb', line 61 def current_image_index current_index % images.size end |
#current_index ⇒ Object
Returns the current animation image count.
54 55 56 |
# File 'lib/metro/animation.rb', line 54 def current_index age / time_per_image end |
#current_time ⇒ Fixnum
Returns the current time in the game.
40 41 42 |
# File 'lib/metro/animation.rb', line 40 def current_time Gosu::milliseconds end |
#image ⇒ Object
Returns a Gosu::Image to be displayed in a animation sequence.
76 77 78 |
# File 'lib/metro/animation.rb', line 76 def image images[current_image_index] end |
#start_time ⇒ Fixnum
Returns the game time when the animation started to display.
33 34 35 |
# File 'lib/metro/animation.rb', line 33 def start_time @start_time ||= current_time end |
#to_hash ⇒ Object
Returns a hash representation of the Animation.
23 24 25 26 27 28 |
# File 'lib/metro/animation.rb', line 23 def to_hash { path: path, width: width.to_i, height: height.to_i, tileable: !!tileable, time_per_image: time_per_image } end |