Jump to content

Need help using PixiJS from npm


Vivraan
 Share

Recommended Posts

Usually, people try set up something with webpack/rollup/whatever_they_want and then complain it doesnt work, post the demo, we resolve it. There are tens of ways to setup pixi with npm and hundreds of associated bugs, which one do you want?

Edited by ivan.popelyshev
Link to comment
Share on other sites

  

I prefer using Rollup for situations like this. A simple Rollup + pixi.js setup could be achieved like so:

1. Use the basic Rollup template from GitHub. You can either click "Use this template" or just clone/download it locally.

2. Open up the template in your favorite code editor and make sure you run `npm install` to install the dependencies needed. You won't need all of the dependencies in production but the template is minimal enough that it's easy to remove unnecessary things later.

3. Rollup will throw some warning because of pixi's usage of url so make the following change on line 17.

// Change this
resolve()

// To this
resolve({ preferBuiltins: false })

4. In the `src/main.js` file, you can add in your pixi code. For example you can use the following to get a rectangle on the screen:

import * as PIXI from 'pixi.js';

const app = new PIXI.Application({ width: 800, height: 600, backgroundColor: 0x1099bb });
document.body.appendChild(app.view);

const rect = new PIXI.Graphics();
rect.beginFill(0xffffff);
rect.lineStyle(5, 0x000000);
rect.drawRect(app.view.width / 2, app.view.height / 2 , 200, 200);

rect.pivot.x = 100;
rect.pivot.y = 100;

app.stage.addChild(rect);

5. Now you can just use the following command

npm run dev

That'll boot up a local dev server with hot reload and if you follow the link you'll see your pixi app working.

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...