Class: Gosu::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/gosu_android/graphics/image.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Image

Returns a new instance of Image.

[View source]

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gosu_android/graphics/image.rb', line 10

def initialize(*args)
  case args.length
  #Argument is ImageData
  when 1
    initialize_1 args[0]
  when 2
    if args[1].class == Bitmap
      initialize_3_bitmap(args[0], args[1])
    else
      initialize_3_file_name(args[0], args[1])
    end
  when 3
    if args[1].class == Bitmap
      initialize_3_bitmap(args[0], args[1], args[2])
    else
      initialize_3_file_name(args[0], args[1], args[2])
    end
  when 6
    if args[1].class == Bitmap
      initialize_7_bitmap(args[0], args[1], args[2], args[3], args[4], args[5])
    else
      initialize_7_file_name(args[0], args[1], args[2], args[3], args[4], args[5])
    end
  when 7
    if args[1].class == Bitmap
      initialize_7_bitmap(args[0], args[1], args[2], args[3], args[4], args[5], args[6])
    else
      initialize_7_file_name(args[0], args[1], args[2], args[3], args[4], args[5], args[6])
    end
  else
    raise ArgumentError
  end
end

Class Method Details

.load_tiles(window, bmp, tile_width, tile_height, tileable) ⇒ Object

[View source]

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/gosu_android/graphics/image.rb', line 120

def self.load_tiles(window, bmp, tile_width, tile_height, tileable)
  images = []

  #If bmp is a file path
  if bmp.class == String or bmp.class == Fixnum
    bmp = Gosu::load_image_file(window, bmp)
  end

  if (tile_width > 0)
    tiles_x = bmp.width / tile_width
  else
    tiles_x = -tile_width
    tile_width = bmp.width / tiles_x
  end

  if (tile_height > 0)
    tiles_y = bmp.height / tile_height
  else
    tiles_y = -tile_height
    tile_height = bmp.height / tiles_y
  end

  tiles_y.times do |y|
    tiles_x.times do |x|
      images.push Image.new(window, bmp, x * tile_width, y * tile_height, tile_width, tile_height, tileable)
    end
  end
  images
end

Instance Method Details

#draw(x, y, z, factor_x = 1, factor_y = 1, c = Color::WHITE, mode = :default) ⇒ Object

[View source]

84
85
86
87
88
# File 'lib/gosu_android/graphics/image.rb', line 84

def draw(x, y, z, factor_x = 1, factor_y = 1, c = Color::WHITE, mode = :default)
  x2 = x + width*factor_x
  y2 = y + height*factor_y      
  @data.draw(x, y, c, x2, y, c, x, y2, c, x2, y2, c, z, AM_MODES[mode])
end

#draw_rot(x, y, z, angle, center_x = 0.5, center_y = 0.5, factor_x = 1.0, factor_y = 1.0, c = Color::WHITE, mode = :default) ⇒ Object

[View source]

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/gosu_android/graphics/image.rb', line 90

def draw_rot(x, y, z, angle, center_x = 0.5, center_y = 0.5, factor_x = 1.0,
  factor_y = 1.0, c = Color::WHITE, mode = :default)

  size_y = width  * factor_x
  size_y = height * factor_y
  offs_x = Gosu::offset_x(angle, 1)
  offs_y = Gosu::offset_y(angle, 1)

  #Offset to the centers of the original Image's edges when it is rotated
  #by <angle> degrees.
  dist_to_left_x   = +offs_y * size_y * center_x
  dist_to_left_y   = -offs_x * size_y * center_x
  dist_to_right_x  = -offs_y * size_y * (1 - center_x)
  dist_to_right_y  = +offs_x * size_y * (1 - center_x)
  dist_to_top_x    = +offs_x * size_y * center_y
  dist_to_top_y    = +offs_y * size_y * center_y
  dist_to_bottom_x = -offs_x * size_y * (1 - center_y)
  dist_to_bottom_y = -offs_y * size_y * (1 - center_y)

  @data.draw(x + dist_to_left_x  + dist_to_top_x,
    y + dist_to_left_y  + dist_to_top_y, c,
    x + dist_to_right_x + dist_to_top_x,
    y + dist_to_right_y + dist_to_top_y, c,
    x + dist_to_left_x  + dist_to_bottom_x,
    y + dist_to_left_y  + dist_to_bottom_y, c,
    x + dist_to_right_x + dist_to_bottom_x,
    y + dist_to_right_y + dist_to_bottom_y,
    c, z, AM_MODES[mode])
end

#heightObject

[View source]

80
81
82
# File 'lib/gosu_android/graphics/image.rb', line 80

def height
  @data.height
end

#widthObject

[View source]

76
77
78
# File 'lib/gosu_android/graphics/image.rb', line 76

def width
  @data.width
end