Skip to main content

Sprites

Creating a new sprite

import cherry0 from "./sprites/cherry-0.png?inline";
import cherry1 from "./sprites/cherry-1.png?inline";

const cherry = mod.resource.sprite.create("cherry", { origin: { x: 10, y: 12 } });
void cherry.load([cherry0, cherry1]);

A sprite is being transmitted while the game is running to allow for dynamically loaded images. Therefore, the sprite isn't immediately ready and the id equals -1 until it is. Check it before drawing:

if (${cherry.id} >= 0) draw_sprite(${cherry.id}, 0, x, y);