PixiJS Visible vs Alpha Properties Explained
In Pixi.js, both the visible and alpha
properties of a DisplayObject control whether an element is
seen on the screen, but they do so in fundamentally different ways. This
article explains the technical differences between these two properties,
how they affect rendering performance, and how they impact user
interactions like mouse clicks and touch events.
The Visible Property
The visible property is a boolean value
(true or false) that determines whether an
object is rendered.
- Rendering and Performance: When you set
visible = false, PixiJS completely skips the object and its entire child hierarchy during the render pass. The engine does not calculate its transforms or send its geometry to the GPU. This makesvisible = falsehighly efficient and the preferred choice for hiding elements to boost game performance. - Interactivity: An object with
visible = falsecannot be interacted with. It will not trigger pointer events, clicks, or hit tests. - Best Use Case: Use
visiblewhen you want to temporarily hide UI menus, off-screen game characters, or any graphics that do not need to be shown or interacted with at the moment.
The Alpha Property
The alpha property is a floating-point number ranging
from 0.0 (fully transparent) to 1.0 (fully
opaque) that controls the opacity of the object.
- Rendering and Performance: Even if you set
alpha = 0, PixiJS still processes the object and its children. The engine calculates their positions, traverses the display tree, and sends the draw calls to the GPU, even though the final output is completely transparent. Consequently, usingalpha = 0is less performant than usingvisible = false. - Interactivity: This is a crucial distinction:
objects with
alpha = 0can still receive interaction events. If an object is interactive, setting its alpha to zero makes it an invisible button that users can still click or tap. - Best Use Case: Use
alphafor visual transitions, such as fading an element in or out over time. It is also ideal for creating invisible hit areas or button zones where you want a region to be clickable without displaying any graphics.
Summary of Key Differences
| Feature | visible = false |
alpha = 0 |
|---|---|---|
| Data Type | Boolean (true /
false) |
Number (0.0 to
1.0) |
| GPU Processing | Completely skipped (Highly efficient) | Processed and rendered (Less efficient) |
| Interactivity / Clicks | Ignored (Cannot be clicked) | Active (Can still trigger events) |
| Child Elements | All children are hidden | All children inherit the transparent alpha |