Class: SpriteSheet

Inherits:
ShaderedSprite show all
Defined in:
scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb

Overview

SpriteSheet is a class that helps the maker to display a sprite from a Sprite Sheet on the screen

Instance Attribute Summary collapse

Attributes inherited from LiteRGSS::ShaderedSprite

#blendmode, #shader

Attributes inherited from LiteRGSS::Sprite

#__index__, #angle, #bitmap, #height, #mirror, #opacity, #ox, #oy, #src_rect, #viewport, #visible, #width, #x, #y, #z, #zoom, #zoom_x, #zoom_y

Instance Method Summary collapse

Methods inherited from Sprite

#load, #mouse_in?, #set_origin_div, #set_rect, #set_rect_div, #set_z, #simple_mouse_in?, #translate_mouse_coords, #update

Methods inherited from LiteRGSS::Sprite

new, #set_origin, #set_position

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Constructor Details

#initialize(viewport, nb_x, nb_y) ⇒ SpriteSheet

Create a new SpriteSheet

Parameters:

  • viewport (Viewport, nil)

    where to display the sprite

  • nb_x (Integer)

    the number of sprites on the x axis in the sheet

  • nb_y (Integer)

    the number of sprites on the y axis in the sheet



19
20
21
22
23
24
25
# File 'scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb', line 19

def initialize(viewport, nb_x, nb_y)
  super(viewport)
  @nb_x = nb_x > 0 ? nb_x : 1
  @nb_y = nb_y > 0 ? nb_y : 1
  @sx = 0
  @sy = 0
end

Instance Attribute Details

#nb_xInteger (readonly)

Return the number of sprite on the x axis of the sheet

Returns:



5
6
7
# File 'scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb', line 5

def nb_x
  @nb_x
end

#nb_yInteger (readonly)

Return the number of sprite on the y axis of the sheet

Returns:



8
9
10
# File 'scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb', line 8

def nb_y
  @nb_y
end

#sxInteger

Return the x sprite index of the sheet

Returns:



11
12
13
# File 'scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb', line 11

def sx
  @sx
end

#syInteger

Return the y sprite index of the sheet

Returns:



14
15
16
# File 'scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb', line 14

def sy
  @sy
end

Instance Method Details

#bitmap=(value)

Change the bitmap of the sprite

Parameters:



29
30
31
32
33
34
35
36
37
# File 'scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb', line 29

def bitmap=(value)
  ret = super(value)
  if value
    w = value.width /  @nb_x
    h = value.height / @nb_y
    src_rect.set(@sx * w, @sy * h, w, h)
  end
  return ret
end

#select(sx, sy) ⇒ self

Select a sprite on the sheet according to its x and y index

Parameters:

  • sx (Integer)

    the x sprite index of the sheet

  • sy (Integer)

    the y sprite index of the sheet

Returns:

  • (self)


57
58
59
60
61
62
# File 'scripts/00700 Ajout_PSDK/00500 SpriteSheet.rb', line 57

def select(sx, sy)
  @sx = sx % @nb_x
  @sy = sy % @nb_y
  src_rect.set(@sx * src_rect.width, @sy * src_rect.height, nil, nil)
  return self
end