Class: Metro::Model::PositionProperty

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

Overview

A position property maintains a 2D Point.

A position property also defines an ‘x` property and a `y` property which allows a more direct interface.

A position is stored as a string in the properties and retrieved as a Point object.

Examples:

Defining a position property, using the x, y and z_order properties


class Enemy < Metro::Model
  property :position

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

Defining a position property providing a default


class Enemy < Metro::Model
  property :position, default: Point.at(44,66)
end

Using a position property with a different property name


class Hero < Metro::Model
  property :pos, type: :position, default: Point.zero

  def draw
    # image.draw pos.x, pos.y, pos.z_order, x_factor, y_factor, color, :add)
    image.draw pos_x, pos_y, pos_z_order, x_factor, y_factor, color, :add)
  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_pointObject



83
84
85
# File 'lib/metro/models/properties/position_property.rb', line 83

def default_point
  Point.parse(options[:default])
end