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

bs-pixi

v0.1.14

Published

buckleScript bindings for PIXI v5

Downloads

20

Readme

STATUS VERSION LICENSE ISSUES

bs-pixi

BuckleScript bindings for PixiJS v6 (Work in progress)

Refer to documentation for existing coverage.

Installation

npm install bs-pixi

And add bs-pixi into bs-dependencies in your project bsconfig.json.

About Bindings

PIXI.js relies heavily on inheritance, which in the context of bucklescript bindings is often realized via functors where module containing subclass functionality would "spread" the implementation of the ancestor module (closest is mixin) - see Extending Modules. This is often referred to as implementation inheritance. One example is in bs-webapi-incubator. In addition to this approach here we bind directly to javascript classes via bucklescript supported class type bindings, with most apis accepting all structural subtypes:

[@bs.send]
external addChild: (Js.t(#C.displayObject), ~child: Js.t(#C.displayObject as 'a)) => Js.t('a) = "addChild";

# denotes structural subtype, so when we see Js.t(#C.displayObjects) we can feed any js object types that are structural subtypes of displayObject directly without upcasting to a type which is defined in a module where addChild is defined. Also this allows us to utilize both functional as well as object apis for the same functionality like:

let point = PIXI.Point.create(~x=1.0, ~y=5.0, ());
let x = point##x;
let x = point |. PIXI.Point.getX;

Although using object methods for anything slightly more complex as simple accessors is not really practical, as [@bs] class object methods do not support currying, labeled and optional parameters, feel free to use it if you feel comfortable with it, as in next example.

Example

open PIXI;

let app = Application.create(~options=Application.createApplicationOptions(
  ~width=800.,
  ~height=600.,
  ~backgroundColor=int_of_string("0x1099bb"),
  ~resolution=DomRe.window |. Obj.magic |. Js.Dict.unsafeGet("devicePixelRatio"), ()), 
  ());

Webapi.Dom.document 
|> Webapi.Dom.Document.asHtmlDocument 
|. Belt.Option.flatMap(document => document |> Webapi.Dom.HtmlDocument.body)
|. Belt.Option.map(body => body |> Webapi.Dom.Element.appendChild(app##view))
|> ignore;

let container = Container.create();

app 
|. Application.getStage 
|. Container.addChild(container);

// Create a new texture
let texture = Texture.from(~source=`String("https://pixijs.io/examples/examples/assets/bunny.png"), ());

// Create a 5x5 grid of bunnies
Belt.Array.range(0, 24)
|. Belt.Array.forEach(i => {
  let bunny = Sprite.create(texture);
  bunny##anchor##set(0.5, 0.5);
  bunny |. Sprite.setX(float_of_int((i mod 5) * 40));
  bunny |. Sprite.setY(floor(float_of_int(i) /. 5.) *. 40.);
  container |. Container.addChild(bunny) |> ignore;
});

container |. Container.setX(app##screen##width /. 2.);
container |. Container.setY(app##screen##height /. 2.);

// Center bunny sprite in local container coordinates
container##pivot##x #= (container##width /. 2.);
container##pivot##y #= (container##height /. 2.);

// Listen for animate update
app
|. Application.getTicker
|. Ticker.add(delta => {
  // rotate the container!
  // use delta to create frame-independent transform
  container |. Container.setRotation(container##rotation -. 0.01 *. delta);
}, ());

Also make sure to CHECK OUT other examples.

Contributing

Any contribution is greatly appreciated. Take a look at CONTRIBUTING.md. Feel free to reach out in issues for any questions.