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.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#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.
- #name ⇒ Object
- #outer_height ⇒ Object
- #position_in!(collection_width) ⇒ Object
- #repeated? ⇒ Boolean
- #right? ⇒ Boolean
- #spacing ⇒ Object
Constructor Details
#initialize(path, options) ⇒ ImageSet
Returns a new instance of ImageSet.
8 9 10 11 12 13 14 |
# File 'lib/spritely/image_set.rb', line 8 def initialize(path, ) @path = path @options = @data = File.read(path) @width, @height = data[0x10..0x18].unpack('NN') @left = 0 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 |
#left ⇒ Object (readonly)
Returns the value of attribute left.
6 7 8 |
# File 'lib/spritely/image_set.rb', line 6 def left @left end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/spritely/image_set.rb', line 6 def @options 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
20 21 22 |
# File 'lib/spritely/image_set.rb', line 20 def images @images ||= [] end |
#name ⇒ Object
16 17 18 |
# File 'lib/spritely/image_set.rb', line 16 def name File.basename(path, ".png") end |
#outer_height ⇒ Object
24 25 26 |
# File 'lib/spritely/image_set.rb', line 24 def outer_height height + spacing end |
#position_in!(collection_width) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/spritely/image_set.rb', line 40 def position_in!(collection_width) if repeated? left_position = 0 while left_position < collection_width add_image!(left_position) left_position += width end elsif right? add_image!(@left = collection_width - width) else add_image!(0) end end |
#repeated? ⇒ Boolean
32 33 34 |
# File 'lib/spritely/image_set.rb', line 32 def repeated? !![:repeat] end |
#right? ⇒ Boolean
36 37 38 |
# File 'lib/spritely/image_set.rb', line 36 def right? [:position] == 'right' end |
#spacing ⇒ Object
28 29 30 |
# File 'lib/spritely/image_set.rb', line 28 def spacing [:spacing] || 0 end |