Class: Airsprite::Sprite
- Inherits:
-
Object
- Object
- Airsprite::Sprite
- Defined in:
- lib/airsprite/base.rb
Instance Attribute Summary collapse
-
#animations ⇒ Object
Returns the value of attribute animations.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sheet ⇒ Object
Returns the value of attribute sheet.
Instance Method Summary collapse
-
#initialize(sheet, name, path) ⇒ Sprite
constructor
A new instance of Sprite.
- #to_s ⇒ Object
Constructor Details
#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 |
Instance Attribute Details
#animations ⇒ Object
Returns the value of attribute animations.
168 169 170 |
# File 'lib/airsprite/base.rb', line 168 def animations @animations end |
#name ⇒ Object
Returns the value of attribute name.
167 168 169 |
# File 'lib/airsprite/base.rb', line 167 def name @name end |
#sheet ⇒ Object
Returns the value of attribute sheet.
167 168 169 |
# File 'lib/airsprite/base.rb', line 167 def sheet @sheet end |
Instance Method Details
#to_s ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/airsprite/base.rb', line 191 def to_s <<-EOS Sprite { name "#{name}" #{animations.map(&:to_s).join} } EOS end |