Class: Metro::Model::AnimationProperty

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

Overview

An animation property manages an Animation, which is an array of Gosu::Images and some metadata.

A animation is stored in the properties as a hash representation and is converted into an Animation when it is retrieved within the system.

The animate images are cached within the animation property to help performance by reducing the unncessary creation of similar animations.

Examples:

Defining an animation property (will default to the missing animation)


class Scoreboard < Metro::Model
  property :animation

  def draw
    animation.image.draw text, x, y, z_order, x_factor, y_factor, color
  end
end

Defining an animation with a path.


class Hero < Metro::Model
  property :animation, path: "star.png", dimensions: Dimensions.of(25,25)
    dimensions: Dimensions.of(25,25) }

  def draw
    animation.image.draw text, x, y, z_order, x_factor, y_factor, color
  end
end

Using an animation property with a different property name


class Hero < Metro::Model
  property :walking, type: :animation, path: "star.png",
    dimensions: Dimensions.of(25,25)

  def draw
    walking.image.draw text, x, y, z_order, x_factor, y_factor, color
  end
end

See Also:

Constant Summary

Constants included from Units

Units::Bounds

Instance Attribute Summary

Attributes inherited from Property

#block, #model, #options

Method Summary

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