Skip to main content

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:

PropertyTypeDescription
shiftXnumberHow much to shift the texture horizontally, in pixels.
shiftYnumberHow much to shift the texture vertically, in pixels.
movementX, movementYnumber

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 u.time into account.

parallaxX, parallaxYnumber

A value that makes background move faster or slower relative to other objects. It is often used to create an effect of depth.

1 means regular movement, values smaller than 1 will make it move slower and make an effect that a background is placed farther away from camera; values larger than 1 will do the opposite, making the background appear closer than the rest of object.

isUibooleanSet it to true for backgrounds that are added to UI layers. It is needed for proper alignment of background layers.
repeatstringOne 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.TilingSpriteopen in new window, and there are some you can find useful:

PropertyTypeDescription
alphanumberOpacity of the layer between 0 and 1. 0 is fully transparent, 1 is fully opaque (default).
tintnumber (hex value)The color of the background. 0xffffff is white (default), 0xff0000 will make it red.
blendModePIXI.BLEND_MODES (number)How to mix the background with the rest of the world. Defaults to PIXI.BLEND_MODES.NORMAL. Can be one of:
  • PIXI.BLEND_MODES.NORMAL
  • PIXI.BLEND_MODES.ADD
  • PIXI.BLEND_MODES.MULTIPLY
  • PIXI.BLEND_MODES.SCREEN