LogoPixi’VN

Canvas component aliases

Aliases for canvas components in Pixi’VN, covering inheritance, editing, and special game layer usage.

Each component added into the canvas must be assigned an alias. An alias is a way to refer to a component by a unique string.

If a component is added by assigning an existing alias, the new component will replace the old one.

The alias corresponds to PixiJSComponent.label, so do not change the label, but use the methods provided by Pixi’VN to change the alias.

Heredity factor

If a component is added using an existing alias, the new component, in addition to replacing the old one, will inherit the properties, the zIndex, and the tickers of the old component.

Edit canvas component alias

To edit the alias of a canvas component, you can use canvas.editAlias. If the alias has one or more tickers associated, it will be automatically updated in the ticker.

The editAlias method has the following parameters:

  • oldAlias: The old alias of the component to edit.
  • newAlias: The new alias of the component.
import { canvas } from '@drincs/pixi-vn'

canvas.editAlias('sprite1', 'sprite2')

Game layer alias

In Pixi’VN, the game layer is a special component that represents the main game area where all the game elements are rendered.

This component has been assigned a special alias, const CANVAS_APP_GAME_LAYER_ALIAS = "__game_layer__", which is used to reference the game layer in the script.

This is very useful if you want to run some animations or effects on the entire layer. Some features are not allowed on this item, such as deletion.

import { CANVAS_APP_GAME_LAYER_ALIAS, shakeEffect } from '@drincs/pixi-vn'

shakeEffect(CANVAS_APP_GAME_LAYER_ALIAS)