npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rul2d

v2.2.4

Published

Rul2d is a powerful and flexible TypeScript library for creating games using HTML5 Canvas.

Readme

Rul2d V2

Rul2d is a powerful and flexible TypeScript library for creating games using HTML5 Canvas.

It provides tools for rendering graphical objects, managing scenes, animations, handling input events (mouse and keyboard).

To install, enter:

npm i rul2d

Template:

import { GameEntity, GameScene, GameWorld, Context } from 'rul2d'

class NewEntity extends GameEntity {
    constructor (x?: number, y?: number) {
        super(x, y)
    }

    protected _init(world: GameWorld): void {
        super._init(world)
    }

    protected async _preload(world: GameWorld): Promise<void> {
        await super._preload(world)
    }

    protected _create(world: GameWorld): DrawableObject[] {
        return [
            ...super._create(world)
        ]
    }

    protected _draw(ctx: Context): void {
        super._draw(ctx)
    }

    protected _update(delta: number): void {
        super._update(delta)
    }
}

class NewScene extends GameScene {
    public test: NewEntity

    constructor () {
        super()
        this.test = new NewEntity()
        this.addObject(this.test)
    }
}

const world = new GameWorld()
world.addScene('new', new NewScene())
world.start()

Example:

import { Camera, Color, Context, DrawMode, GameEntity, GameScene, GameWorld, Point, Rectangle, Size, VectorUtils } from 'rul2d'

class TestEntity extends GameEntity {
    private rectangle: Rectangle
    private direction: Point
    private speed: number
    private camera: Camera
    private size: Size

    constructor (x?: number, y?: number) {
        super(x, y)

        this.direction = new Point(1)
        this.speed = 200
        this.size = new Size()
        this.camera = new Camera()
        this.rectangle = new Rectangle()
    }

    protected _init({camera}: GameWorld): void {
        this.camera = camera
    }

    protected _create(world: GameWorld): DrawableObject[] {
        this.rectangle.setPosition(1000, 500)
        this.rectangle.setSize(100)
        this.rectangle.setColor(Color.Black)
        this.rectangle.setDrawMode(DrawMode.Fill)

        return [
            this.rectangle
        ]
    }

    protected _update(delta: number): void {
        let {x, y, bottom, right} = this.camera.viewport
        if(this.rectangle.x <= x || this.rectangle.right >= right) this.direction.x *= -1
        if(this.rectangle.y <= y || this.rectangle.bottom >= bottom) this.direction.y *= -1

        this.move(
            VectorUtils.multiplyOnNumber(this.direction, this.speed), 
            delta
        )
    }
}

class TestScene extends GameScene {
    public test: TestEntity

    constructor () {
        super()
        this.test = new TestEntity()
        this.create()
    }

    create(): void {
        this.addObject(this.test)
    }
}

const world = new GameWorld()
Camera.addStandardWheelListener(world.camera)
world.addScene('test', new TestScene())
world.start()
world.log()

Links