Method: MiniGL::Sprite#initialize

Defined in:
lib/minigl/game_object.rb

#initialize(x, y, img, sprite_cols = nil, sprite_rows = nil, retro = nil) ⇒ Sprite

Creates a new sprite.

Parameters:

x

The x-coordinate in the screen (or map) where the sprite will be drawn. This can be modified later via the x attribute.

y

The y-coordinate in the screen (or map) where the sprite will be drawn. This can be modified later via the y attribute.

img

The path to a PNG image or spritesheet, following the MiniGL convention: images must be inside a ‘data/img’ directory, relative to the code file, and you must only provide the file name, without extension, in this case. If the image is inside a subdirectory of ‘data/img’, you must prefix the file name with each subdirectory name, followed by an underscore (so the file and directories names must not contain underscores). For example, if your image is ‘data/img/sprite/1.png’, you must provide "sprite_1" or :sprite_1.

sprite_cols

The number of columns in the spritesheet. Use nil if the image is not a spritesheet.

sprite_rows

The number of rows in the spritesheet. Use nil if the image is not a spritesheet.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/minigl/game_object.rb', line 35

def initialize(x, y, img, sprite_cols = nil, sprite_rows = nil, retro = nil)
  @x = x; @y = y
  retro = Res.retro_images if retro.nil?
  @img =
    if sprite_cols.nil?
      [Res.img(img, false, false, '.png', retro)]
    else
      Res.imgs img, sprite_cols, sprite_rows, false, '.png', retro
    end
  @anim_counter = 0
  @img_index = 0
  @index_index = 0
  @animate_once_control = 0
end