Class: Metro::UI::Sprite
Overview
A sprite is a Metro model that is specially designed to draw and manage an image. A sprite maintains an image, location information, and rotation.
Direct Known Subclasses
Constant Summary
Constants included from Metro::Units
Instance Attribute Summary collapse
-
#angle ⇒ Object
The angle at which the sprite should be drawn.
-
#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.
-
#image ⇒ Object
The image that will be drawn for 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.
-
#draw ⇒ Object
By default the sprite will draw the image defined for it.
-
#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, #create, #draw_completed?, hierarchy, inherited, #initialize, metro_name, #model, model_name, models, #name, #notification, #saveable_to_view, #show, #to_hash, #update, #update_completed?
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.
38 |
# File 'lib/metro/models/ui/sprite.rb', line 38 property :angle |
#center_x ⇒ Object
The center, horizontal position, as expressed in a ratio, of the image.
30 |
# File 'lib/metro/models/ui/sprite.rb', line 30 property :center_x, type: :numeric, default: 0.5 |
#center_y ⇒ Object
The center, vertical position, as expressed in a ratio, of the image.
34 |
# File 'lib/metro/models/ui/sprite.rb', line 34 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.
22 |
# File 'lib/metro/models/ui/sprite.rb', line 22 property :color |
#dimensions ⇒ Object
The height and width of the sprite is based on the image of the sprite.
42 43 44 |
# File 'lib/metro/models/ui/sprite.rb', line 42 property :dimensions do image.dimensions end |
#image ⇒ Object
The image that will be drawn for the sprite
12 |
# File 'lib/metro/models/ui/sprite.rb', line 12 property :image |
#position ⇒ Object
The point at which the sprite should be drawn
16 |
# File 'lib/metro/models/ui/sprite.rb', line 16 property :position |
#scale ⇒ Object
The scale at which to draw the sprite. This is default scale of 1.
26 |
# File 'lib/metro/models/ui/sprite.rb', line 26 property :scale |
Instance Method Details
#bottom ⇒ Float
67 68 69 |
# File 'lib/metro/models/ui/sprite.rb', line 67 def bottom top + height * y_factor end |
#bounds ⇒ RectangleBounds
47 48 49 |
# File 'lib/metro/models/ui/sprite.rb', line 47 def bounds Bounds.new left: left, right: right, top: top, bottom: bottom end |
#draw ⇒ Object
By default the sprite will draw the image defined for it.
74 75 76 |
# File 'lib/metro/models/ui/sprite.rb', line 74 def draw image.draw_rot x, y, z_order, angle, center_x, center_y, x_factor, y_factor, color end |
#left ⇒ Float
52 53 54 |
# File 'lib/metro/models/ui/sprite.rb', line 52 def left x - width * center_x * x_factor end |
#right ⇒ Float
57 58 59 |
# File 'lib/metro/models/ui/sprite.rb', line 57 def right left + width * x_factor end |
#top ⇒ Float
62 63 64 |
# File 'lib/metro/models/ui/sprite.rb', line 62 def top y - height * center_y * y_factor end |