# LittleJS

Build a LittleJS game with your bundler of choice and ship it to Wavedash.

Source: https://docs.wavedash.com/engines/littlejs

<GithubLink href="https://github.com/wvdsh/examples/tree/main/example-littlejs" />
<PlaytestLink href="https://wavedash.com/playtest/littlejs-example/aa576ea7-0a40-423a-8a3d-1ac68a11a88f" />

[LittleJS](https://github.com/KilledByAPixel/LittleJS) is a tiny, zero-dependency HTML5 game engine in a single JavaScript file. It uses WebGL for rendering and ships with input, audio, physics, particles, and tilemap helpers — all in a few dozen KB.

LittleJS works with any JavaScript bundler — Vite, Webpack, Rollup, esbuild, Parcel, and others. This page covers the generic setup. [The example repo](https://github.com/wvdsh/examples/tree/main/example-littlejs) uses Vite.

## Install dependencies

```bash
npm install littlejsengine
npm install @wvdsh/sdk-js
```

`@wvdsh/sdk-js`'s default export is the live, fully-typed Wavedash SDK singleton.

## Wire up `Wavedash.init()`

In the file where you call `engineInit(...)`, import `Wavedash` and call `init()` inside `gameInit`.

<Urgent>
**Calling `Wavedash.init()` is required.** Your game stays hidden behind the Wavedash loading screen until you do. Call it once your game is ready to play.
</Urgent>

```typescript
import Wavedash from "@wvdsh/sdk-js";
import { engineInit, vec2, setCameraPos, setCameraScale } from 'littlejsengine';

Wavedash.updateLoadProgressZeroToOne(0.3);

function gameInit() {
  // Your game's one-time setup.
  Wavedash.init({ debug: true });
}

function gameUpdate()     { /* per-frame logic */ }
function gameUpdatePost() { /* after physics */ }
function gameRender()     { /* WebGL draw */ }
function gameRenderPost() { /* UI / overlays */ }

engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, []);
```

Call `updateLoadProgressZeroToOne(...)` during async asset loading; `init()` automatically signals load completion, so call it last.

## wavedash.toml

Point `upload_dir` at your bundler's output directory. For Vite and most other bundlers that's `./dist`.

```toml
game_id = "YOUR_GAME_ID_HERE"
upload_dir = "./dist"
```

## Local development

Produce a build, then run `wavedash dev` to serve it through the Wavedash sandbox.

## SDK features

Once initialized, `Wavedash` exposes leaderboards, achievements, stats, and user data:

```javascript
const user = Wavedash.getUser();

const lb = await Wavedash.getLeaderboard("high-scores");
await Wavedash.uploadLeaderboardScore(lb.data.id, score, true);

Wavedash.setAchievement("first_win", true);
```
