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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tawaship/pixi-box2d

v1.0.3

Published

"pixi-box2d" is a plugin for using "[box2dweb](https://github.com/hecht-software/box2dweb)" with "[pixi.js](https://github.com/pixijs/pixi.js)".

Downloads

3

Readme

pixi-box2d

"pixi-box2d" is a plugin for using "box2dweb" with "pixi.js".

Build Status MIT License


Supported version

  • box2dweb 2.1.0-b
  • pixi.js 5.3.x

I have not confirmed the operation on other versions.

Setup

NPM

npm install --save pixi.js @tawaship/pixi-box2d
import * as PIXI from 'pixi.js';
import * as PixiBox2d from '@tawaship/pixi-box2d';

Browser

git clone https://github.com/tawaship/pixi-box2d
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.3.3/pixi.min.js"></script>
<script src="/path/to/lib/Box2d.min.js"></script>
<script src="/path/to/dist/pixi-box2d.min.js"></script>

Usage

For browsers, this module is stored in the namespace "PIXI.box2d".

const app = new PIXI.Application({
	width: 450,
	height: 800
});

class Root extends PIXI.Container {
	constructor() {
		super();
		
		this.addChild(new PIXI.Graphics()).beginFill(0x00FF00).drawRect(0, 0, 450, 800 / 2)
		this.interactive = true;
		this.cursor = 'pointer'
		
		// create World
		const world = this.addChild(new PIXI.box2d.WorldContainer({
			listenPreSolve: false,
			listenPostSolve: false,
			listenBeginContact: false,
			listenEndContact: true,
			ticker: app.ticker
		}));
		
		// create component
		const a = world.addBox2d(PIXI.box2d.Circle.from(new PIXI.Graphics().beginFill(0xFF0000).drawCircle(100, 0, 20), {
			density: 0.1,
			restitution: 0.1,
			categoryBits: 2
		}));
		a.setX(120);
		
		// create component when click
		this.on("pointerdown", (e) => {
			const r = Math.random() > 0.5;
			const w = 100
			const h = 150
			
			const a2 = world.addBox2d(new PIXI.box2d.Rectangle(w, h, {
				density: 0.1,
				restitution: 0.1,
				friction: 0.9,
				categoryBits: 1
			}));
			
			a2.addChild(new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, w, h));
			
			if (!r) {
				a2.setX(e.data.global.x - a2.width / 2);
				a2.setY(e.data.global.y - a2.height / 2);
			} else {
				a2.setRotation(90 * Math.PI / 180);
				a2.setX(e.data.global.x + a2.height / 2);
				a2.setY(e.data.global.y - a2.width / 2);
			}
		})
		
		// create static component
		const baseHeight = 100;
		const base = world.addBox2d(PIXI.box2d.Rectangle.from(new PIXI.Graphics().beginFill(0x0000FF).drawRect(0, 0, 450 / 2, baseHeight), { isStatic: true }));
		base.setX(450 / 2 - base.width / 2);
		base.setY(800 - baseHeight - 100);
		
		// create sensor component
		const dead = world.addBox2d(new PIXI.box2d.Edge(new PIXI.box2d.Common.Math.b2Vec2(450 + 2000, 0), { isStatic: true, isSensor: true, maskBits: 1 }));
		dead.setX(-1000);
		dead.setY(800 - 10);
		dead.on('EndContact', (opponent) => {
			world.removeBox2d(opponent);
			console.log("gameover");
		});
	}
}

app.stage.addChild(new Root());
document.body.appendChild(app.view);