# Melonjs Sprites And Animation

Use this skill when creating sprites, playing frame animations, or working with texture...

- Repository: https://github.com/melonjs/melonJS (6430 stars)
- Category: Design
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add melonjs/melonJS --skill melonjs-sprites-and-animation -g -a claude-code -y`
Codex: `npx skills add melonjs/melonJS --skill melonjs-sprites-and-animation -g -a codex -y`
Cursor: `npx skills add melonjs/melonJS --skill melonjs-sprites-and-animation -g -a cursor -y`
Gemini CLI: `npx skills add melonjs/melonJS --skill melonjs-sprites-and-animation -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add melonjs/melonJS`

## Description

Use this skill when creating sprites, playing frame animations, or working with texture atlases in melonJS. Covers Sprite construction from a plain image or an atlas region, addAnimation/setCurrentAnimation, TextureAtlas for TexturePacker/ShoeBox/Aseprite, tint, flip, NineSliceSprite, and the centred anchorPoint that offsets naive positioning. Triggers on: Sprite, new Sprite, addAnimation, setCurrentAnimation, isCurrentAnimation, TextureAtlas, TexturePacker, Aseprite, ShoeBox, atlas, region, framewidth, frameheight, tint, flipX, flipY, NineSliceSprite, animation.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Sprites, animation and atlases

> Creating sprites from images or atlases, driving frame animation, and the
> positioning trap that catches almost everyone.

## `pos` is the centre, not the top-left

`Renderable.anchorPoint` defaults to **`(0.5, 0.5)`**, so a sprite's `pos` is its
**centre**. `Container` forces `(0, 0)` instead, which is why containers and
sprites appear to disagree.

```js
// a 64×64 sprite at (100, 100) covers 68..132, not 100..164
const s = new Sprite(100, 100, { image: "hero", framewidth: 64, frameheight: 64 });

s.anchorPoint.set(0, 0);   // switch to top-left positioning if you prefer
```

Writing top-left maths against the centred default puts everything half a sprite
off, with no error. It is the most common source of "close but subtly wrong"
placement.

## Constructing a sprite

From a plain image:

```js
const hero = new Sprite(x, y, {
    image: "hero",          // preloaded asset name
    framewidth: 32,
    frameheight: 32,
});
```

From a texture atlas region:

```js
const atlas = new TextureAtlas(loader.getJSON("sprites"), loader.getImage("sprites"));
const coin = new Sprite(x, y, { image: atlas, region: "coin_01.png" });
```

`framewidth` / `frameheight` define the animation grid on a sheet. Omit them and
the whole image is one frame.

## Animation

```js
hero.addAnimation("idle", [0, 1, 2, 3], 100);   // frames, ms per frame
hero.addAnimation("walk", [4, 5, 6, 7]);
hero.addAnimation("die",  [8, 9], 150);

The rest: https://github.com/melonjs/melonJS/blob/HEAD/packages/melonjs/skills/melonjs-sprites-and-animation/SKILL.md
