Background class
Background
class
Here you will find properties that allow changing speed, position, repeat pattern and parallax effect of backgrounds in-game, among other properties like tint
and alpha
.
Positioning and movement
Each background has these properties that set how background is positioned in the viewport:
Property | Type | Description |
---|---|---|
shiftX | number | How much to shift the texture horizontally, in pixels. |
shiftY | number | How much to shift the texture vertically, in pixels. |
movementX , movementY | number | The speed at which the background's texture moves by X and Y axes, wrapping around its area. The value is measured in pixels per second. It also takes |
parallaxX , parallaxY | number | A value that makes background move faster or slower relative to other objects. It is often used to create an effect of depth.
|
isUi | boolean | Set it to true for backgrounds that are added to UI layers. It is needed for proper alignment of background layers. |
repeat | string | One of 'repeat' , 'repeat-x' , 'repeat-y' , or 'no-repeat' . |
Adding a background
Backgrounds can only be added through backgrounds.add
method.
Removing a background
Similar to templates, a background can be removed with bg.kill = true;
, where bg
is the backgrond that needs to be removed.
Other interesting properties
Backgrounds inherit lots of properties and methods of PIXI.TilingSprite
, and there are some you can find useful:
Property | Type | Description |
---|---|---|
alpha | number | Opacity of the layer between 0 and 1. 0 is fully transparent, 1 is fully opaque (default). |
tint | number (hex value) | The color of the background. 0xffffff is white (default), 0xff0000 will make it red. |
blendMode | PIXI.BLEND_MODES (number ) | How to mix the background with the rest of the world. Defaults to PIXI.BLEND_MODES.NORMAL . Can be one of:
|