Method: Airsprite::Sprite#initialize

Defined in:
lib/airsprite/base.rb

#initialize(sheet, name, path) ⇒ Sprite

Returns a new instance of Sprite.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/airsprite/base.rb', line 170

def initialize(sheet, name, path)
  @name = name
  @animations = []

  if File.directory?(path)
    Dir["#{path}*/"].each do |dir|
      @animations += [SpriteAnimation.new(dir.split('/').last, dir)]
    end
  else
    @animations += [SpriteAnimation.new('idle', path)]
  end

  if @animations.map(&:frames).flatten.map(&:width).uniq.size > 1
    raise "Widths of frames for a sprite must be the same width"
  end

  if @animations.map(&:frames).flatten.map(&:height).uniq.size > 1
    raise "Widths of frames for a sprite must be the same height"
  end
end