Function

loadSpriteAtlas

(src: LoadSpriteSrc, data: SpriteAtlasData): Asset<Record<string, SpriteData>>

Load sprites from a sprite atlas.

param src- The image resource url.

param data- The sprite atlas data.

// See #SpriteAtlasData type for format spec
loadSpriteAtlas("sprites/dungeon.png", {
    "hero": {
        x: 128,
        y: 68,
        width: 144,
        height: 28,
        sliceX: 9,
        anims: {
            idle: { from: 0, to: 3 },
            run: { from: 4, to: 7 },
            hit: 8,
        },
    },
});

const player = add([
    sprite("hero"),
]);

player.play("run");

returns The asset data.

since v2000.0

group Assets

Function

loadSpriteAtlas

(src: LoadSpriteSrc, url: string): Asset<Record<string, SpriteData>>

Load sprites from a sprite atlas with URL.

param src- The image resource url.

param url- The json resource url.

// Load from json file, see #SpriteAtlasData type for format spec
loadSpriteAtlas("sprites/dungeon.png", "sprites/dungeon.json")

const player = add([
    sprite("hero"),
])

player.play("run")

returns The asset data.

since v2000.0

group Assets

kaplay logo

Layer

Miscalenous