Class: Gosu::Image

Inherits:
Object
  • Object
show all
Includes:
Chingu::NamedResource
Defined in:
lib/chingu/assets.rb,
lib/chingu/gosu_ext/image.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Chingu::NamedResource

included, #name, #name=

Class Method Details

.autoload(name) ⇒ Object



35
36
37
38
39
# File 'lib/chingu/assets.rb', line 35

def self.autoload(name)
  ret = (path = find_file(name)) ? Gosu::Image.new($window, path, false) : nil
  raise "Can't load image \"#{name}\"" if ret.nil?
  return ret
end

Instance Method Details

#retrofyObject

Retrofy should be called just after the image is loaded. When retrofied an image will use a non-blurry zoom. This could be used to make each pixel a sharp 4 pixelblock => retrofeeling.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chingu/gosu_ext/image.rb', line 45

def retrofy
  Gosu::enable_undocumented_retrofication
  self
  
  #
  # The below code depends on the bad opengl gem
  # And it could affect other images anyhow... 
  # So let's use Gosu::enable_undocumented_retrofication until further notice.
  #
  
  #glBindTexture(GL_TEXTURE_2D, self.gl_tex_info.tex_name)
  #glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  #glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
  #self
end

#transparent_pixel?(x, y) ⇒ Boolean

Returns true if the pixel at x, y is 100% transperant (good for collisiondetection) Requires texplay

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/chingu/gosu_ext/image.rb', line 32

def transparent_pixel?(x, y)
  begin
    self.get_pixel(x,y)[3] == 0
  rescue
    puts "Error in get_pixel at x/y: #{x}/#{y}: #{$!}"
  end
end