SpriteRenderer

The SpriteRenderer component renders an image (sprite) to the screen. It supports slicing, scaling, rotation, flipping, opacity, color masking, tinting, and tiling. It uses the entity’s Transform for position. See Rendering for an overview.

Options

OptionTypeDefaultDescription
imageHTMLImageElement | stringThe image to render, or an asset URL/name string.
layerstring"Default"The render layer.
sliceSliceRegion of the image to draw ({ x, y, width, height }).
widthnumberOverrides the rendered width.
heightnumberOverrides the rendered height.
scaleVector2(1, 1)Scales the image.
offsetVector2(0, 0)Offset from the entity’s position.
rotationnumber0Rotation in radians.
flipHorizontallybooleanfalseFlips the image horizontally.
flipVerticallybooleanfalseFlips the image vertically.
opacitynumber1Opacity between 0 and 1.
tintColorstringColor used to tint the image.
maskColorstringMask color applied to the image.
maskColorMixnumberMask color opacity between 0 and 1.
tiledVector2Tiles the image across the given number of columns and rows.
smoothbooleanfalseSmooths pixels. Not recommended for pixel art.

Example

import { Transform, SpriteRenderer } from "angry-pixel";

this.entityManager.createEntity([
    new Transform(),
    new SpriteRenderer({
        image: this.assetManager.getImage("player.png"),
        layer: "Default",
    }),
]);

The image is loaded through the asset manager, typically in the scene’s loadAssets method. Animated sprites are driven by the Animator component.