Class: Metro::UI::AnimatedSprite

Inherits:
Model
  • Object
show all
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

Metro::Units::Bounds

Instance Attribute Summary collapse

Attributes inherited from Model

#scene, #window

Instance Method Summary collapse

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

included

Methods included from KeyValueCoding

#get, #set

Methods included from PropertyOwner

included, #properties

Constructor Details

This class inherits a constructor from Metro::Model

Instance Attribute Details

#angleObject

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

#animationObject

The animation that will be drawn for the sprite



13
# File 'lib/metro/models/ui/animated_sprite.rb', line 13

property :animation

#center_xObject

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.0

#center_yObject

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.0

#colorObject

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

#dimensionsObject

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

#positionObject

The point at which the sprite should be drawn



17
# File 'lib/metro/models/ui/animated_sprite.rb', line 17

property :position

#scaleObject

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

#bottomFloat

Returns the bottom-most y position of the sprite.

Returns:

  • (Float)

    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

#boundsRectangleBounds

Returns the bounds of the sprite.

Returns:



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_imageGosu::Image

Returns the current image in the animation sequence.

Returns:

  • (Gosu::Image)

    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

#drawObject

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

#leftFloat

Returns the left-most x position of the sprite.

Returns:

  • (Float)

    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

#rightFloat

Returns the right-most x position of the sprite.

Returns:

  • (Float)

    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

#topFloat

Returns the top-most y position of the sprite.

Returns:

  • (Float)

    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