Class: Metro::UI::AnimatedSprite
- Defined in:
- lib/metro/models/ui/animated_sprite.rb
Overview
A sprite is a Metro model that is specially designed to draw and manage an animation. A sprite maintains an animation, location information, and rotation.
Constant Summary
Constants included from Metro::Units
Instance Attribute Summary collapse
-
#angle ⇒ Object
The angle at which the sprite should be drawn.
-
#animation ⇒ Object
The animation that will be drawn for the sprite.
-
#center_x ⇒ Object
The center, horizontal position, as expressed in a ratio, of the image.
-
#center_y ⇒ Object
The center, vertical position, as expressed in a ratio, of the image.
-
#color ⇒ Object
This is the color of the spirte.
-
#dimensions ⇒ Object
The height and width of the sprite is based on the image of the sprite.
-
#position ⇒ Object
The point at which the sprite should be drawn.
-
#scale ⇒ Object
The scale at which to draw the sprite.
Attributes inherited from Model
Instance Method Summary collapse
-
#bottom ⇒ Float
The bottom-most y position of the sprite.
-
#bounds ⇒ RectangleBounds
The bounds of the sprite.
-
#current_image ⇒ Gosu::Image
The current image in the animation sequence.
-
#draw ⇒ Object
By default the sprite will draw the current image of the animation.
-
#left ⇒ Float
The left-most x position of the sprite.
-
#right ⇒ Float
The right-most x position of the sprite.
-
#top ⇒ Float
The top-most y position of the sprite.
Methods inherited from Model
#_load, #_save, #after_initialize, #completed?, #create, hierarchy, inherited, #initialize, metro_name, #model, model_name, models, #name, #notification, #saveable_to_view, #show, #to_hash, #update
Methods included from HasEvents
Methods included from KeyValueCoding
Methods included from PropertyOwner
Constructor Details
This class inherits a constructor from Metro::Model
Instance Attribute Details
#angle ⇒ Object
The angle at which the sprite should be drawn. This is by default 0.
39 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 39 property :angle |
#animation ⇒ Object
The animation that will be drawn for the sprite
13 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 13 property :animation |
#center_x ⇒ Object
The center, horizontal position, as expressed in a ratio, of the image.
31 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 31 property :center_x, type: :numeric, default: 0.5 |
#center_y ⇒ Object
The center, vertical position, as expressed in a ratio, of the image.
35 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 35 property :center_y, type: :numeric, default: 0.5 |
#color ⇒ Object
This is the color of the spirte. The color usually remains white, and the color property is implemented by the ‘alpha` value is the one thing that is altered to fade in and fade out the sprite.
23 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 23 property :color |
#dimensions ⇒ Object
The height and width of the sprite is based on the image of the sprite.
43 44 45 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 43 property :dimensions do Dimensions.of current_image.width, current_image.height end |
#position ⇒ Object
The point at which the sprite should be drawn
17 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 17 property :position |
#scale ⇒ Object
The scale at which to draw the sprite. This is default scale of 1.
27 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 27 property :scale |
Instance Method Details
#bottom ⇒ Float
Returns the bottom-most y position of the sprite.
68 69 70 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 68 def bottom top + height * y_factor end |
#bounds ⇒ RectangleBounds
Returns the bounds of the sprite.
48 49 50 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 48 def bounds Bounds.new left: left, right: right, top: top, bottom: bottom end |
#current_image ⇒ Gosu::Image
Returns the current image in the animation sequence.
73 74 75 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 73 def current_image animation.image end |
#draw ⇒ Object
By default the sprite will draw the current image of the animation.
80 81 82 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 80 def draw current_image.draw_rot x, y, z_order, angle, center_x, center_y, x_factor, y_factor, color end |
#left ⇒ Float
Returns the left-most x position of the sprite.
53 54 55 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 53 def left x - width * center_x end |
#right ⇒ Float
Returns the right-most x position of the sprite.
58 59 60 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 58 def right left + width * x_factor end |
#top ⇒ Float
Returns the top-most y position of the sprite.
63 64 65 |
# File 'lib/metro/models/ui/animated_sprite.rb', line 63 def top y - height * center_y end |