Class: AdventureRL::Image

Inherits:
Mask show all
Includes:
Helpers::Error
Defined in:
lib/AdventureRL/Image.rb

Direct Known Subclasses

Animation

Constant Summary collapse

DEFAULT_SETTINGS =
Settings.new(
  file:              'DEFAULT_IMAGE_FILE.png',
  retro:             true,
  z_index:           0,
  dont_create_image: false,  # Used by Animation
  position: {
    x: 0,
    y: 0
  },
  size: {
    width:  128,
    height: 128
  },
  origin: {
    x: :left,
    y: :top
  }
)
IMAGE_OPTION_KEYS =

Valid image option keys for the Gosu::Image constructor.

[
  :tileable,
  :retro,
  :rect
]

Constants included from Helpers::Error

Helpers::Error::PADDING, Helpers::Error::STACK_TRACE_PADDING, Helpers::Error::STACK_TRACE_SIZE

Constants inherited from Mask

Mask::MASKS

Constants inherited from Point

Point::POINTS

Instance Method Summary collapse

Methods included from Helpers::Error

directory_exists?, error, error_no_directory, error_no_file, file_exists?

Methods inherited from Mask

#assign_to, #assigned_to?, #collides_with?, #collides_with_hash?, #collides_with_mask?, #collides_with_point?, #get_assigned, #get_center, #get_corner, #get_layer, #get_mask, #get_origin, #get_real_center, #get_real_corner, #get_real_side, #get_real_sides, #get_side, #get_sides, #get_size, #has_layer?, #has_mask?, #set_layer, #set_size

Methods inherited from Point

#assign_to, #assigned_to?, #collides_with?, #collides_with_hash?, #collides_with_mask?, #collides_with_point?, #get_assigned, #get_layer, #get_point, #get_position, #get_real_point, #get_real_position, #has_layer?, #has_point?, #keys, #move_by, #set_layer, #set_position, #values, #x, #y

Constructor Details

#initialize(settings = {}) ⇒ Image

Pass the filepath to the image as the value of the key :file in your passed Settings instance or hash.



33
34
35
36
37
38
39
# File 'lib/AdventureRL/Image.rb', line 33

def initialize settings = {}
  @settings = DEFAULT_SETTINGS.merge settings
  @z_index       = @settings.get :z_index
  @image_options = get_image_options_from @settings
  @image         = get_image_from @settings.get(:file)  unless (@settings.get(:dont_create_image))
  super @settings
end

Instance Method Details

#drawObject



41
42
43
44
45
46
47
48
49
# File 'lib/AdventureRL/Image.rb', line 41

def draw
  corner = get_corner :left, :top
  scale  = get_image_scale
  @image.draw(
    corner.x, corner.y,
    @z_index,
    scale[:x], scale[:y]
  )
end