Class: Metro::UI::Image

Inherits:
Model
  • Object
show all
Defined in:
lib/metro/models/ui/image.rb

Overview

The image will draw an image with the specifie path, color, rotation, and scale.

Examples:

Drawing the ‘player.png’ image at (320,240)


class MainScene < GameScene
  draw :player, model: "metro::ui::image", position: "320,240",
    image: "player.png"
end

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 to draw the image



33
# File 'lib/metro/models/ui/image.rb', line 33

property :angle, type: :numeric, default: 0

#center_xObject

The center x position of the image as expressed in a scale of from left to right (0.0 to 1.0).



38
# File 'lib/metro/models/ui/image.rb', line 38

property :center_x, type: :numeric, default: 0.5

#center_yObject

The center y position of the image as expressed in a scale of from top to bottom (0.0 to 1.0).



43
# File 'lib/metro/models/ui/image.rb', line 43

property :center_y, type: :numeric, default: 0.5

#colorObject

The color of the image, by default this is white to display the image as normal, but this can be used to augment the look of the image. Mostly color is use for the sub-property :alpha which allows an image to be faded-in and faded-out



29
# File 'lib/metro/models/ui/image.rb', line 29

property :color

#dimensionsObject

The dimensions of the image.



51
52
53
# File 'lib/metro/models/ui/image.rb', line 51

property :dimensions do
  image.dimensions
end

#imageObject

The image asset to draw.



47
# File 'lib/metro/models/ui/image.rb', line 47

property :image

#positionObject

The position of the image



18
# File 'lib/metro/models/ui/image.rb', line 18

property :position

#scaleObject

The scale of the image



22
# File 'lib/metro/models/ui/image.rb', line 22

property :scale, default: Scale.one

Instance Method Details

#boundsObject



55
56
57
# File 'lib/metro/models/ui/image.rb', line 55

def bounds
  Bounds.new left: left_x, right: right_x, top: top_y, bottom: bottom_y
end

#drawObject



59
60
61
62
63
64
65
# File 'lib/metro/models/ui/image.rb', line 59

def draw
  image.draw_rot x, y, z_order,
    angle.to_f,
    center_x, center_y,
    x_factor, y_factor,
    color
end