Class: Yuki::Parallax_Object

Inherits:
Object
  • Object
show all
Defined in:
scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb

Overview

Object that describe a parallax as a particle

Author:

  • Nuri Yuri

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image, x, y, z, zoom_x = 1, zoom_y = 1, opacity = 255, blend_type = 0) ⇒ Parallax_Object

Creates a new Parallax_Object

Parameters:

  • image (String)

    name of the image in Graphics/Pictures/

  • x (Integer)

    x coordinate of the parallax from the first pixel of the Map (16x16 tiles /!)

  • y (Integer)

    y coordinate of the parallax from the first pixel of the Map (16x16 tiles /!)

  • z (Integer)

    z superiority in the tile viewport

  • zoom_x (Numeric) (defaults to: 1)

    zoom_x of the parallax

  • zoom_y (Numeric) (defaults to: 1)

    zoom_y of the parallax

  • opacity (Integer) (defaults to: 255)

    opacity of the parallax (0~255)

  • blend_type (Integer) (defaults to: 0)

    blend_type of the parallax (0, 1, 2)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb', line 26

def initialize(image, x, y, z, zoom_x = 1, zoom_y = 1, opacity = 255, blend_type = 0)
  @sprite = ::Sprite.new(Particles.viewport, true)
  @sprite.z = z
  @sprite.zoom_x = zoom_x
  @sprite.zoom_y = zoom_y
  @sprite.opacity = opacity
  @sprite.blend_type = blend_type
  @sprite.bitmap = ::RPG::Cache.picture(image)
  @x = x + MapLinker.get_OffsetX * 16
  @y = y + MapLinker.get_OffsetY * 16
  @factor_x = 0
  @factor_y = 0
  @map_id = $game_map.map_id
  update
end

Instance Attribute Details

#disposedBoolean (readonly) Also known as: disposed?

If the parallax is disposed

Returns:

  • (Boolean)


7
8
9
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb', line 7

def disposed
  @disposed
end

#factor_xNumeric

the factor that creates an automatic offset in x

Returns:

  • (Numeric)


13
14
15
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb', line 13

def factor_x
  @factor_x
end

#factor_yNumeric

the factor that creates an automatic offset in y

Returns:

  • (Numeric)


16
17
18
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb', line 16

def factor_y
  @factor_y
end

#spriteSprite

The parallax sprite

Returns:



10
11
12
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb', line 10

def sprite
  @sprite
end

Instance Method Details

#dispose

Dispose the parallax



54
55
56
57
58
59
60
61
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb', line 54

def dispose
  return if disposed?

  @sprite.dispose unless @sprite.disposed?
  @sprite = nil
  @disposed = true
  Yuki::Particles.clean_stack
end

#update

Update the parallax position



43
44
45
46
47
48
49
50
51
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00504 Parallax_Object.rb', line 43

def update
  return if disposed?
  return dispose if @map_id != $game_map.map_id

  dx = $game_map.display_x / 8
  dy = $game_map.display_y / 8
  @sprite.x = (@x - dx) + (@factor_x * dx)
  @sprite.y = (@y - dy) + (@factor_y * dy)
end