Class: Gosu::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/ashton/gosu_ext/image.rb

Constant Summary collapse

DEFAULT_DRAW_COLOR =
Gosu::Color::WHITE

Instance Method Summary collapse

Instance Method Details

#cacheObject

The cache is a replacement for Texplay’s pixel cache system.



88
89
90
# File 'lib/ashton/gosu_ext/image.rb', line 88

def cache
  @cache ||= Ashton::PixelCache.new self
end

#draw(*args) ⇒ Object



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/ashton/gosu_ext/image.rb', line 7

def draw(*args)
  args, shader = if args.last.is_a?(Hash)
                   [args[0..-2], args.last[:shader]]
                 else
                   [args, nil]
                 end

  z = args[2]

  if shader
    shader.enable z
    $window.gl z do
      shader.image = self
      shader.color = args[5].is_a?(Color) ? args[5] : DEFAULT_DRAW_COLOR
    end
  end

  begin
    draw_without_hash(*args)
  ensure
    shader.disable z if shader
  end
end

#draw_as_points(points, z, options = {}) ⇒ Object

Draw a list of centred sprites by position.

TODO: Need to use point sprites here, but this is still much faster than individual #draws if using shaders and comparable if not.

Parameters:

  • points (Array<Array>)

    Array of [x, y] positions

  • z (Float)

    Z-order to draw - Ignored if shader is used.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :scale (Float) — default: 1.0

    Relative size of the sprites

  • :shader (Ashton::Shader)

    Shader to apply to all sprites.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ashton/gosu_ext/image.rb', line 64

def draw_as_points(points, z, options = {})
  color = options[:color] || DEFAULT_DRAW_COLOR
  scale = options[:scale] || 1.0
  shader = options[:shader]
  mode = options[:mode] || :default

  if shader
    shader.enable z
    $window.gl z do
      shader.image = self
      shader.color = color
    end
  end

  begin
    points.each do |x, y|
      draw_rot_without_hash x, y, z, 0, 0.5, 0.5, scale, scale, color, mode
    end
  ensure
    shader.disable z if shader
  end
end

#draw_rot(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ashton/gosu_ext/image.rb', line 33

def draw_rot(*args)
  args, shader = if args.last.is_a?(Hash)
                   [args[0..-2], args.last[:shader]]
                 else
                   [args, nil]
                 end
  z = args[2]

  if shader
    shader.enable z
    $window.gl z do
      shader.image = self
      shader.color = args[8].is_a?(Color) ? args[8] : DEFAULT_DRAW_COLOR
    end
  end

  begin
    draw_rot_without_hash(*args)
  ensure
    shader.disable z if shader
  end
end

#to_textureObject



92
93
94
# File 'lib/ashton/gosu_ext/image.rb', line 92

def to_texture
  Ashton::Texture.new self
end