# asepriter

> An library for using animations exported from Aseprite.

Latest version **1.0.2** (published 2022-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install asepriter
pnpm add asepriter
yarn add asepriter
bun add asepriter
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-09-20 |
| First published | 2022-09-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 797.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | lazygyu |
| Maintainers | lazygyu |
| Keywords | ase, aseprite, sprite, animation |

## Links

- npm: https://www.npmjs.com/package/asepriter
- Repository: https://github.com/lazygyu/asepriter
- Issues: https://github.com/lazygyu/asepriter/issues
- npm.io page: https://npm.io/package/asepriter

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2022-09-20
- 1.0.1 — 2022-09-19
- 1.0.0 — 2022-09-19

## README

# Summary

A library for loading and rendering animations exported by Aseprite.

# Install

```shell
> yarn add asepriter
```

# Usage

## Simple Usage

```typescript
import { Asepriter } from "asepriter";

const jsonUrl = '/assets/animation.json';
const imageUrl = '/assets/animation.png';

(async () => {
	const canvas = document.querySelector('#canv') as HTMLCanvasElement;
	const instance = await Asepriter.create(jsonUrl, imageUrl);

	let lastTimestamp = performance.now();
	let deltaTime = 0;

	const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
	const render = (timestamp: number) => {

		deltaTime = timestamp - lastTimestamp;
		lastTimestamp = timestamp;

		const animation = instance.getAnimation(instance.animationKeys[0]);
		animation.update(deltaTime);

		ctx.clearRect(0, 0, canvas.width, canvas.height);
		ctx.drawImage(animation.currentFrame.image, 0, 0);

		requestAnimationFrame(render);
	}

	instance.on('load', () => {
			render(performance.now());
	});
})();
```

## Other Usage

See `example/index.ts`

# Development

## check example code

```shell
> yarn dev
```

# Todos

* [x] load the json and the image file
	* [x] parse the json data
	* [x] get frames and create separated images
	* [x] load tags into animations
* [x] draw a sprite
	* [x] get a specific sprite
* [x] draw an animation
	* [x] get an animation by a tag name
	* [x] update the frame number of the animation by time
	* [x] get the current sprite of the animation
* [x] clone an Asepriter instance.
* [x] share sprite images among animations that have the same data
* [x] emit 'done' event when an animation has ended
* [x] build script
* [ ] Documentation

---
_Source: https://npm.io/package/asepriter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
