kaplayjs/kaplay
{ "createdAt": "2024-05-21T15:14:33Z", "defaultBranch": "master", "description": "๐ฆ A JavaScript/TypeScript Game Library that feels like a game.", "fullName": "kaplayjs/kaplay", "homepage": "https://kaplayjs.com", "language": "TypeScript", "name": "kaplay", "pushedAt": "2025-11-27T00:01:39Z", "stargazersCount": 1342, "topics": [ "game-dev", "game-development", "game-engine", "game-library", "javascript", "kaboom-js", "kaboomjs", "typescript" ], "updatedAt": "2025-11-27T00:01:43Z", "url": "https://github.com/kaplayjs/kaplay"}๐ฎ KAPLAY.js โ A JavaScript & TypeScript Game Library
Section titled โ๐ฎ 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
Section titled โ๐ฒ Quick Overviewโ// Start a gamekaplay({ background: "#6d80fa",});
// Load an imageloadSprite("bean", "https://play.kaplayjs.com/bean.png");
// Add a sprite to the sceneadd([ 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 componentconst 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" componentplayer.onCollide("enemy", () => { // .hp comes from "health" component player.hp--;});
// check fall deathplayer.onUpdate(() => { if (player.pos.y >= height()) { destroy(player); }});
// All objects with tag "enemy" will move to the leftonUpdate("enemy", (enemy) => { enemy.move(-400, 0);});
// move up 100 pixels per second every frame when "w" key is held downonKeyDown("w", () => { player.move(0, 100);});๐ฅ๏ธ Installation
Section titled โ๐ฅ๏ธ Installationโ๐ Using create-kaplay
Section titled โ๐ Using create-kaplayโThe fastest way to get started:
npx create-kaplay my-gameThen open http://localhost:5173 and edit src/game.js.
๐ฆ Install with package manager
Section titled โ๐ฆ Install with package managerโnpm install kaplayyarn add kaplaypnpm add kaplaybun add kaplayYou will need a bundler like Vite or ESBuild to use KAPLAY in your project. Learn how to setup ESbuild here.
๐ Use in Browser
Section titled โ๐ Use in BrowserโInclude via CDN:
<script src="https://unpkg.com/kaplay@3001.0.12/dist/kaplay.js"></script>๐ TypeScript Global Types
Section titled โ๐ 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
Section titled โ๐ Resourcesโ๐ Docs
Section titled โ๐ Docsโ๐บ Tutorials
Section titled โ๐บ Tutorialsโ- ๐ฅ KAPLAY Library Crash Course by JSLegend โ๏ธ
- ๐ Learn JavaScript basics and KAPLAY to make games quickly
๐ฌ Community
Section titled โ๐ฌ Communityโ๐ฎ Games
Section titled โ๐ฎ GamesโCollections of games made with KAPLAY, selected by KAPLAY:
๐ Credits
Section titled โ๐ 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
Section titled โ๐ Recognitionsโ- Thanks to mulfok for the awesome mulfok32 color palette, used in KAPLAY sprites and art
- Thanks to Pixabay for the great
burp sound, used in
burp()function - Thanks to Kenney for all used assets for examples
- Thanks to abrudz for the amazing APL386 font
- Thanks to Polyducks for the amazing kitchen sink font font
- Thanks to 0x72 for the amazing Dungeon Tileset