gitmyhub

notpygamejs

JavaScript ★ 109 updated 2y ago

Game making library for using Canvas element

A minimal JavaScript library by Andrej Karpathy for building simple 2D browser games on Canvas, handling the game loop, timing, and input so you just write init/update/draw functions.

JavaScriptHTML Canvassetup: easycomplexity 2/5

Plain-English Explanation: notpygamejs

notpygamejs is a lightweight JavaScript library that makes it easier to build games that run in a web browser using the Canvas element. Instead of wrestling with low-level browser APIs for drawing, timing, and input handling, you write a few simple functions and the library handles the boring plumbing—like running a game loop at a steady frame rate and capturing mouse clicks and keyboard presses.

Here's how it works at a high level. You create an HTML page with a canvas (the rectangular drawing area where your game appears), then you write five core functions: an initialization function that runs once when the game starts, an update function that runs repeatedly to handle game logic, a draw function that paints graphics each frame, and two event handlers for mouse clicks and keyboard input. The library automatically calls these functions in the right order and at the right speed, typically 30 to 50 times per second, so your game feels smooth and responsive.

Who would use this? Anyone building a simple 2D game for the web—think puzzle games, interactive art projects, educational demos, or prototypes. For example, if you wanted to build a breakout paddle game, you'd write a function to update the paddle position based on keyboard input, another function to draw the paddle and ball, and a third to detect collisions. The library handles the rest: keeping time, running the animation loop, and passing you input events.

The main tradeoff is simplicity over features. This isn't a full game engine like those used for professional games; it's intentionally minimal and was created as a teaching tool (by Andrej Karpathy in 2012). There's no physics engine, no sprite system, no asset management. You're drawing directly to the canvas context, which means you have full control but also more responsibility. It's a good fit if you want to learn how games work under the hood or build something quick without heavyweight dependencies.

Where it fits