Class: RubySprites::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/lash-sprites/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, sprite, x = 0, y = 0, width = nil, height = nil) ⇒ Image

Returns a new instance of Image.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lash-sprites/image.rb', line 7

def initialize(path, sprite, x = 0, y = 0, width = nil, height = nil)
  @path = path
  @sprite = sprite
  @x = x
  @y = y

  @width = nil
  @height = nil

  if exists?
    
    if !sprite.mtime.nil? && mtime < sprite.mtime
      @width = width
      @height = height
    end

    if @width.nil? || @height.nil?
      info = @sprite.graphics_manager.get_info(path)
      @width = info[:width]
      @height = info[:height]
    end
  end
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/lash-sprites/image.rb', line 5

def height
  @height
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/lash-sprites/image.rb', line 5

def path
  @path
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/lash-sprites/image.rb', line 5

def width
  @width
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/lash-sprites/image.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/lash-sprites/image.rb', line 4

def y
  @y
end

Instance Method Details

#areaObject



35
36
37
38
39
# File 'lib/lash-sprites/image.rb', line 35

def area
  return nil if @width.nil?
  @area = @width * @height if @area.nil?
  return @area
end

#exists?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/lash-sprites/image.rb', line 31

def exists?
  return File.exists?(@sprite.file_root + @path)
end

#mtimeObject



41
42
43
44
# File 'lib/lash-sprites/image.rb', line 41

def mtime
  return File.mtime(@sprite.file_root + @path) if exists?
  return nil
end