Class: Airsprite::SpriteAnimation
- Inherits:
-
Object
- Object
- Airsprite::SpriteAnimation
- Defined in:
- lib/airsprite/base.rb
Instance Attribute Summary collapse
-
#frames ⇒ Object
Returns the value of attribute frames.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, path) ⇒ SpriteAnimation
constructor
A new instance of SpriteAnimation.
- #to_s ⇒ Object
Constructor Details
#initialize(name, path) ⇒ SpriteAnimation
Returns a new instance of SpriteAnimation.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/airsprite/base.rb', line 207 def initialize(name, path) @name = name @frames = [] if File.directory?(path) Dir["#{path}*.png"].each do |file| @frames << SpriteFrame.new(File.basename(file, '.png'), file) end else @frames << SpriteFrame.new(File.basename(path, '.png'), path) end @frames.sort_by(&:name).inject(0) do |position, frame| frame.position = position position + 1 end end |
Instance Attribute Details
#frames ⇒ Object
Returns the value of attribute frames.
205 206 207 |
# File 'lib/airsprite/base.rb', line 205 def frames @frames end |
#name ⇒ Object
Returns the value of attribute name.
204 205 206 |
# File 'lib/airsprite/base.rb', line 204 def name @name end |
Instance Method Details
#to_s ⇒ Object
225 226 227 228 229 230 231 232 233 234 |
# File 'lib/airsprite/base.rb', line 225 def to_s <<-EOS SpriteAnimation { name "#{name}" #{frames.sort_by(&:position).map(&:to_s).join} } EOS end |