Class: Metro::Model::ColorProperty

Inherits:
Property
  • Object
show all
Defined in:
lib/metro/models/properties/color_property.rb

Overview

A color property maintains a Gosu::Color.

A color property also defines an alpha property which allows a more direct interface to setting the alpha property on the color. This is useful in cases for images where the color remains as white but the alpha value needs to be adjusted.

A color is stored in the properties as a string representation and is converted into a Gosu::Color when it is retrieved within the system.

Examples:

Defining a color property using the color properties default


class Hero < Metro::Model
  property :color

  def draw
    image.draw x, y, z_order, x_factor, y_factor, color, :add)
  end

end

Defining a color property providing a default


class Hero < Metro::Model
  property :color, default: "rgba(255,0,0,1.0)"
end

Using the alpha property


class Hero < Metro::Model
  property :color, default: "rgba(255,0,0,1.0)"

  def become_ghost!
    self.alpha = 127
  end
end

Using a color property with a different property name


class Hero < Metro::Model
  property :color
  property :invincible_color, type: :color, default: "rgba(255,0,255,1.0)"

  def draw
    if invincible?
      image.draw x, y, z_order, x_factor, y_factor, invincible_color, :add)
    else
      image.draw x, y, z_order, x_factor, y_factor, color, :add)
    end
  end
end

Constant Summary

Constants included from Units

Units::Bounds

Instance Attribute Summary

Attributes inherited from Property

#block, #model, #options

Instance Method Summary collapse

Methods inherited from Property

define_property, defined_properties, get, #get, get_or_set, gets, hash_with_default_to_nil, inherited, #initialize, properties, properties_hash, property, #set, set, sets

Constructor Details

This class inherits a constructor from Metro::Model::Property

Instance Method Details

#default_colorObject

Returns the default color of the color property. This can be set during initialization by usign the option ‘default`.

Returns:

  • the default color of the color property. This can be set during initialization by usign the option ‘default`.



99
100
101
# File 'lib/metro/models/properties/color_property.rb', line 99

def default_color
  create_color(default_color_string)
end