Jump to content

Understanding Pixi.js v5.x Loaders


jSwtch
 Share

Recommended Posts

Looking at the github basic usage example => Why is the ticker nested inside the loader?

const app = new PIXI.Application();
document.body.appendChild(app.view);

app.loader.add('bunny', 'bunny.png').load((loader, resources) => {
    const bunny = new PIXI.Sprite(resources.bunny.texture);

    bunny.x = app.renderer.width / 2;
    bunny.y = app.renderer.height / 2;

    bunny.anchor.x = 0.5;
    bunny.anchor.y = 0.5;

    app.stage.addChild(bunny);

    app.ticker.add(() => {
        bunny.rotation += 0.01;
    });
});

I am comparing to this example (https://pixijs.io/examples/#/demos-basic/tinting.js

PIXI.Sprite.from(...

Is there a significant difference between this syntax?

new PIXI.Sprite(...

Also in this tinting example they are setting:

dude.turningSpeed = 

 I don't seem to be able to set these type of custom properties using the Github basic usage example.

I created this codepen that shows the problem I have of all sprites acting together https://codepen.io/jswtch/pen/gJBaBz?editors=0010

 

 

 

Link to comment
Share on other sites

0. difference is that from() creates texture before image is actually loaded. Only when its loaded texture size is changed, contents are uploaded to videomemory. It stores images in cache.

1. app.loader.add("bunny", bunnyURL, {crossOrigin: '*'}) - that was your problem. You can also pass crossOrigin to from() but i dont remember how.

2. you can assign any property, its JS. 'turningSpeed" works only because its actually used somewhere in ticker handler in the same example.

Link to comment
Share on other sites

52 minutes ago, ivan.popelyshev said:

0. difference is that from() creates texture before image is actually loaded. Only when its loaded texture size is changed, contents are uploaded to videomemory. It stores images in cache

Is this from method generally preferred?

 

 

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