javascriptpixi.js

PIxiJS TilingSprite not rendered


I've got a simple PixiJS code to add a tiling sprite to scene. The issue is, the ordinary sprite renders OK (which means asset texture exists and loads OK), but the tiling sprite doesn't. I use PixiJS 8.x.

const app = new PIXI.Application();

await app.init({ width: 1750, height: 1500 })
document.body.appendChild(app.canvas);

const t = await PIXI.Assets.load('res/grasstile.jpg');
const po1 = new PIXI.Sprite(t);
const po2 = new PIXI.TilingSprite({ t, width: 1000, height: 1000 });
app.stage.addChild(po2);
app.stage.addChild(po1);

Solution

  • You're passing a t key but it needs to be texture, use the followinG:

    const po2 = new PIXI.TilingSprite({ texture: t, width: 1000, height: 1000 });
    

    Or, if you really want to use the short object notation, you'll need to rename t to texture, like so:

    const texture = await PIXI.Assets.load('res/grasstile.jpg');
    const po1 = new PIXI.Sprite(texture);
    const po2 = new PIXI.TilingSprite({ texture, width: 1000, height: 1000 });
    app.stage.addChild(po2);
    app.stage.addChild(po1);