Class: NuriYuri::DynamicLight::DynamicLightSprite

Inherits:
Sprite show all
Defined in:
scripts/02000 Nuri Yuri/00001 DynamicLight/00002 DynamicLightSprite.rb

Overview

Sprite that simulate the dynamic light

Direct Known Subclasses

ScalableDLS

Constant Summary collapse

DIRECTION_OFFSET =

Offset of the light in :direction mode

-12
# Offset of the light in other modes
NORMAL_OFFSET =

Offset of the light in other modes

-8
# Zoom of a tile to process coodinate properly
TILE_ZOOM =

Zoom of a tile to process coodinate properly

Configs.display.tilemap_settings.character_tile_zoom

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

Methods inherited from LiteRGSS::Sprite

new, #set_origin, #set_position

Methods inherited from LiteRGSS::Disposable

#disposed?

Constructor Details

#initialize(character, light_type, animation_type = 0, zoom_count = 0, opacity_count = 0) ⇒ DynamicLightSprite

Create a new DynamicLightSprite

Parameters:

  • character (Game_Character)
  • light_type (Integer)

    Type of the light we'll display on the character

  • animation_type (Integer) (defaults to: 0)

    Type of the animation performed on the light

  • zoom_count (Integer) (defaults to: 0)

    initial value of the zoom_count

  • opacity_count (Integer) (defaults to: 0)

    initial value of the opacity_count



21
22
23
24
25
26
27
28
29
30
31
# File 'scripts/02000 Nuri Yuri/00001 DynamicLight/00002 DynamicLightSprite.rb', line 21

def initialize(character, light_type, animation_type = 0, zoom_count = 0, opacity_count = 0)
  super(DynamicLight.viewport)
  @character = character
  load_light(LIGHTS[light_type])
  animation = ANIMATIONS[animation_type]
  @zoom_list = animation[:zoom]
  @zoom_count = zoom_count
  @opacity_list = animation[:opacity]
  @opacity_count = opacity_count
  @tile_zoom = TILE_ZOOM
end

Instance Attribute Details

#light_idInteger

Returns ID of the light in the stack.

Returns:

  • (Integer)

    ID of the light in the stack



13
14
15
# File 'scripts/02000 Nuri Yuri/00001 DynamicLight/00002 DynamicLightSprite.rb', line 13

def light_id
  @light_id
end

Instance Method Details

#dispose

Dispose the sprite



57
58
59
60
# File 'scripts/02000 Nuri Yuri/00001 DynamicLight/00002 DynamicLightSprite.rb', line 57

def dispose
  @sub_sprite&.dispose
  super
end

#update

Update the sprite



34
35
36
37
38
39
40
41
42
43
44
# File 'scripts/02000 Nuri Yuri/00001 DynamicLight/00002 DynamicLightSprite.rb', line 34

def update
  @opacity_count = (@opacity_count + 1) % @opacity_list.size
  @zoom_count = (@zoom_count + 1) % @zoom_list.size
  return unless visible

  self.zoom = @zoom_list[@zoom_count]
  self.opacity = @opacity_list[@opacity_count]
  set_position((@character.screen_x * @tile_zoom).floor, (@character.screen_y * @tile_zoom).floor + @offset_y)
  sub_sprite_update if @sub_sprite
  update_direction if @mode == :direction
end

#visible=(value) Also known as: on=

Change the sprite visibility

Parameters:

  • value (Boolean)


51
52
53
54
# File 'scripts/02000 Nuri Yuri/00001 DynamicLight/00002 DynamicLightSprite.rb', line 51

def visible=(value)
  super
  @sub_sprite.visible = value if @sub_sprite
end