Class: Spritely::ImageSet
- Inherits:
-
Object
- Object
- Spritely::ImageSet
- Defined in:
- lib/spritely/image_set.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#top ⇒ Object
Returns the value of attribute top.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #images ⇒ Object
-
#initialize(path, options) ⇒ ImageSet
constructor
A new instance of ImageSet.
- #left ⇒ Object
- #name ⇒ Object
- #position_in!(collection_width) ⇒ Object
- #repeated? ⇒ Boolean
Constructor Details
#initialize(path, options) ⇒ ImageSet
8 9 10 11 12 13 |
# File 'lib/spritely/image_set.rb', line 8 def initialize(path, ) @path = path = @data = File.read(path) @width, @height = data[0x10..0x18].unpack('NN') end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/spritely/image_set.rb', line 6 def data @data end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/spritely/image_set.rb', line 6 def height @height end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/spritely/image_set.rb', line 6 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/spritely/image_set.rb', line 6 def path @path end |
#top ⇒ Object
Returns the value of attribute top.
5 6 7 |
# File 'lib/spritely/image_set.rb', line 5 def top @top end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/spritely/image_set.rb', line 6 def width @width end |
Instance Method Details
#images ⇒ Object
19 20 21 |
# File 'lib/spritely/image_set.rb', line 19 def images @images ||= [] end |
#left ⇒ Object
23 24 25 |
# File 'lib/spritely/image_set.rb', line 23 def left 0 end |
#name ⇒ Object
15 16 17 |
# File 'lib/spritely/image_set.rb', line 15 def name File.basename(path, ".png") end |
#position_in!(collection_width) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spritely/image_set.rb', line 31 def position_in!(collection_width) if repeated? left = 0 while left < collection_width add_image!(left) left += width end else add_image!(0) end end |
#repeated? ⇒ Boolean
27 28 29 |
# File 'lib/spritely/image_set.rb', line 27 def repeated? !![:repeat] end |