Class: Spritely::ImageSet

Inherits:
Object
  • Object
show all
Defined in:
lib/spritely/image_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ ImageSet



8
9
10
11
12
13
# File 'lib/spritely/image_set.rb', line 8

def initialize(path, options)
  @path = path
  @options = options
  @data = File.read(path)
  @width, @height = data[0x10..0x18].unpack('NN')
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def data
  @data
end

#heightObject (readonly)

Returns the value of attribute height.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def height
  @height
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/spritely/image_set.rb', line 6

def path
  @path
end

#topObject

Returns the value of attribute top.



5
6
7
# File 'lib/spritely/image_set.rb', line 5

def top
  @top
end

#widthObject (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

#imagesObject



19
20
21
# File 'lib/spritely/image_set.rb', line 19

def images
  @images ||= []
end

#leftObject



23
24
25
# File 'lib/spritely/image_set.rb', line 23

def left
  0
end

#nameObject



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?
  !!options[:repeat]
end