kaplay is a free, open source gaming project written in TypeScript and released under MIT. It has 1,828 GitHub stars, 132 forks and 76 open issues, and was last pushed 15 hours ago. On this registry it ranks #70 of 86 tracked projects in Gaming, with 5 head-to-head comparisons available. It gained 1 stars over the last 2 tracked days.

What is kaplay?

KAPLAY is a 2D game library for JavaScript and TypeScript, released under the MIT licence, that lets developers describe games as lists of composable components and try them immediately in a browser-based editor, the KAPLAYGROUND โ€” it is aimed at both beginners learning game development and experienced developers who want a small library rather than a full engine.

What it is

KAPLAY is a JavaScript and TypeScript game library distributed as the kaplay package on npm and usable directly in the browser through a CDN script tag. Its model is component composition: a developer calls kaplay() once to start a game, then adds game objects by passing a list of components such as sprite(), rect(), pos(), area(), body() and health() to add(), attaching plain data objects and string tags alongside them. Behaviour is expressed imperatively through handlers such as player.onCollide("enemy", ...), onUpdate("enemy", ...) and onKeyDown("w", ...).

The concrete problem it solves is the hand-written plumbing that otherwise surrounds a small 2D game: the library supplies the game loop, asset loading through calls like loadSprite("bean", "https://play.kaplayjs.com/bean.png"), collision and physics responses, input handling and object lifecycle management through destroy(). It lives in the JavaScript and TypeScript ecosystem, so it slots into an existing front-end project rather than requiring a separate engine runtime; the README notes that a bundler such as Vite or ESBuild is needed when the library is installed through a package manager. A web-based editor, the KAPLAYGROUND, and more than 90 examples accompany it for learning and quick experiments.

Key capabilities

  • Starting a game with configuration options, as in kaplay({ background: "#6d80fa" }).
  • Building game objects from component lists, for example add([rect(40, 40), pos(100, 200), area(), body(), health(8)]).
  • Attaching tags and plain data fields to objects so groups can be queried, as with onUpdate("enemy", (enemy) => { ... }).
  • Collision callbacks supplied by the area() component, used through player.onCollide("enemy", ...).
  • Sprite loading from a URL with loadSprite().
  • Installation through npm, yarn, pnpm or bun, via a CDN script tag in the browser, or by scaffolding with npx create-kaplay.
  • TypeScript support through import "kaplay/global" for global types, a tsconfig.json types entry pointing at ./node_modules/kaplay/dist/declaration/global.d.ts, or source types imported from kaplay, such as TextCompOpt.

Who uses it and how

  • Beginners can write and run code instantly in the KAPLAYGROUND, using more than 90 examples as a starting point.
  • Developers with an existing JavaScript or TypeScript front end can add the library to a project already built with Vite or ESBuild.
  • Small browser-only projects can load the library from a CDN script tag without any build step at all.
  • TypeScript teams can choose between global types for convenience and namespace-style imports from kaplay for stricter control.
  • Finished games are collected on itch.io and Newgrounds, where the project maintains curated playlists of games made with the library.

Getting started

The fastest route is npx create-kaplay my-game, after which the project is available at http://localhost:5173 for editing in src/game.js. Alternatively, install the kaplay package with npm, yarn, pnpm or bun and pair it with a bundler such as Vite or ESBuild.

How it compares

The facts provided list no paid products that KAPLAY replaces, and the only other project named anywhere in them is Kaboom.js, which appears as the kaboom-js and kaboomjs topic tags. No comparable game library is described in this registry entry, so on the evidence given KAPLAY stands alone here.

When to use it โ€” and when not to

KAPLAY runs in the browser, so a self-hoster operates no database, storage service or mail server โ€” only static hosting for the built game โ€” but installing it through a package manager does mean adding a bundler to the toolchain. Teams that do not work in JavaScript or TypeScript, or that want to avoid build tooling entirely, are better served elsewhere. The README itself cautions against relying on the global namespace when publishing a game rather than testing or learning, recommending explicit type configuration instead, and the repository currently carries 76 open issues.

project readme (upstream, from github) โ€” read inline

๐ŸŽฎ KAPLAY.js โ€” A JavaScript & TypeScript Game Library

KAPLAY is the fun-first, 2D game library for JavaScript and TypeScript. Itโ€™s made to feel like a game while you're making games. Simple. Fast. Powerful.

โœจ Whether youโ€™re a beginner or an experienced dev, KAPLAY comes with its own web-based editor โ€” the KAPLAYGROUND โ€” so you can try code instantly, and learn with more than 90 examples!

๐ŸŽฒ Quick Overview

// Start a game
kaplay({
    background: "#6d80fa",
});

// Load an image
loadSprite("bean", "https://play.kaplayjs.com/bean.png");

// Add a sprite to the scene
add([
    sprite("bean"), // it renders as a sprite
]);

Game objects are composed from simple, powerful components:

// Add a Game Obj to the scene from a list of components
const player = add([
    rect(40, 40), // it renders as a rectangle
    pos(100, 200), // it has a position (coordinates)
    area(), // it has a collider
    body(), // it is a physical body which will respond to physics
    health(8), // it has 8 health points
    // Give it tags for easier group behaviors
    "friendly",
    // Give plain objects fields for associated data
    {
        dir: vec2(-1, 0),
        dead: false,
        speed: 240,
    },
]);

Blocky imperative syntax for describing behaviors

// .onCollide() comes from "area" component
player.onCollide("enemy", () => {
    // .hp comes from "health" component
    player.hp--;
});

// check fall death
player.onUpdate(() => {
    if (player.pos.y >= height()) {
        destroy(player);
    }
});

// All objects with tag "enemy" will move to the left
onUpdate("enemy", (enemy) => {
    enemy.move(-400, 0);
});

// move up 100 pixels per second every frame when "w" key is held down
onKeyDown("w", () => {
    player.move(0, 100);
});

๐Ÿ–ฅ๏ธ Installation

๐Ÿš€ Using create-kaplay

The fastest way to get started:

npx create-kaplay my-game

Then open http://localhost:5173 and edit src/game.js.

๐Ÿ“ฆ Install with package manager

npm install kaplay
yarn add kaplay
pnpm add kaplay
bun add kaplay

You will need a bundler like Vite or ESBuild to use KAPLAY in your project. Learn how to setup ESbuild here.

๐ŸŒ Use in Browser

Include via CDN:

<script src="https://unpkg.com/kaplay@3001.0.12/dist/kaplay.js"></script>

๐Ÿ“œ TypeScript Global Types

If you're using TypeScript, you used create-kaplay or installed with a package manager and you want global types, you can load them using the following directive:

import "kaplay/global";

vec2(10, 10); // typed!

But it's recommended to use tsconfig.json to include the types:

{
  "compilerOptions": {
    "types": ["./node_modules/kaplay/dist/declaration/global.d.ts"]
  }
}

[!WARNING]
If you are publishing a game (and not testing/learning) maybe you don't want to use globals, see why.

You can also use all KAPLAY source types importing them:

import type { TextCompOpt } from "kaplay"
import type * as KA from "kaplay" // if you prefer a namespace-like import

interface MyTextCompOpt extends KA.TextCompOpt {
  fallback: string;
}

๐Ÿ“š Resources

๐Ÿ“– Docs

๐Ÿ“บ Tutorials

๐Ÿ’ฌ Community

๐ŸŽฎ Games

Collections of games made with KAPLAY, selected by KAPLAY:

๐Ÿ™Œ Credits

KAPLAY is an open-source project, maintained by the KAPLAY Team and core contributors and with the support of many other amazing contributors.

๐Ÿ† Recognitions

Frequently asked questions

Is kaplay free to use?

kaplay is open source under the MIT licence. There is no licence fee and no seat count โ€” you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does kaplay do?

๐Ÿฆ– A JavaScript/TypeScript Game Library that feels like a game.

What is kaplay written in?

kaplay is primarily written in TypeScript. Its source is publicly available at https://github.com/kaplayjs/kaplay, and it has 1,828 GitHub stars.