Jump to content

A virtual dom library for Pixi.js snabbpixi


eguneys
 Share

Recommended Posts

I've written a virtual dom library for pixi.js. https://github.com/eguneys/snabbpixi

It only supports `PIXI.Container` and `PIXI.Sprite` but you can extend it to work for custom display containers.

It's used like this:

import * as PIXI from 'pixi.js';
import { init } from 'snabbpixi';
import { h } from 'snabbpixi';

const app = new PIXI.Application({});

app.loader
  .add("")
  .load(() => {

    let patch, vnode;

    function redraw() {
      vnode = patch(vnode, view());
    }

    patch = init([]);

    const blueprint = view();
    vnode = patch(app.stage, blueprint);
  };

function view() {
  return h('container', [
    h('sprite', {
     texture: PIXI.Texture.from('image.png')
    }),
    h('sprite', {
      texture: PIXI.Texture.from('image.png')
      x: 10,
      y: 10,
      height: 100,
      width: 100
    });
  ]);
}

 

Please take a look and use it, I will try to improve it as I make more games.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...