Class: Airsprite::SpriteAnimation

Inherits:
Object
  • Object
show all
Defined in:
lib/airsprite/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#framesObject

Returns the value of attribute frames.



205
206
207
# File 'lib/airsprite/base.rb', line 205

def frames
  @frames
end

#nameObject

Returns the value of attribute name.



204
205
206
# File 'lib/airsprite/base.rb', line 204

def name
  @name
end

Instance Method Details

#to_sObject



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