The SpriteRenderer component renders 2D images (sprites) to the screen.
It supports features like image slicing, scaling, rotation, flipping, opacity, color masking and tinting.
Images can be rendered with custom dimensions, positioned with offsets, and even tiled across an area.
The component allows control over pixel smoothing and can be assigned to specific render layers.

const spriteRenderer = new SpriteRenderer({
image: this.assetManager.getImage("image.png"),
width: 1920,
height: 1080,
offset: new Vector2(0, 0),
flipHorizontally: false,
flipVertically: false,
rotation: 0,
opacity: 1,
maskColor: "#FF0000",
maskColorMix: 0,
tintColor: "#00FF00",
layer: "Default",
slice: {x: 0, y: 0, width: 1920, height: 1080},
scale: new Vector2(1, 1),
tiled: new Vector2(1, 1),
smooth: false
});

Constructors

Properties

flipHorizontally: boolean = false

Flip the image horizontally

flipVertically: boolean = false

Flip the image vertically

height: number

Overwrite the original image height

image: string | HTMLImageElement

The image to render

layer: string = defaultRenderLayer

The render layer

maskColor: string

Define a mask color for the image

maskColorMix: number

Define the opacity of the mask color between 1 and 0

offset: Vector2 = ...

X-axis and Y-axis offset

opacity: number = 1

Change the opacity between 1 and 0

rotation: number = 0

Image rotation in radians

scale: Vector2 = ...

Scale the image based on a vector

slice?: Slice

Cut the image based on straight coordinates starting from the top left downward

smooth: boolean = false

TRUE for smooth pixels (not recommended for pixel art)

tiled: Vector2

Enable tiled draw mode

tintColor: string

Define a color for tinting the sprite image

width: number

Overwrite the original image width