Sign in to follow this  
lars

pixi spritesheet image reference

Recommended Posts

Hi All

I'm trying to setup a spritesheet like this:



this.myLoader = new PIXI.Loader();
       this.myLoader
        .add("images","assets/images/props.png")
        .add("json","assets/images/props.json")
       .load(startGame());



function startGame(){
let spritesheetPropsTexture = PIXI.Texture.from("assets/images/props.png");
        let spritesheetPropsSprite = new PIXI.Sprite(spritesheetPropsTexture);
        let mySheet = new PIXI.Spritesheet(spritesheetPropsSprite.texture.baseTexture,"assets/images/props.json");


        let cheese = new PIXI.Sprite(myspritesheet.textures["cheese.png"]);

}

I know that it´s fairly simpel like this:


        let sheet = PIXI.Loader.shared.resources["assets/images/props.json"].spritesheet;
        let cheese =  new PIXI.Sprite(sheet.textures["cheese.png"]);
with the shared loader.
 
But i need to have a reference to the image. Anyone knows how to solve this.

Share this post


Link to post
Share on other sites

It´s working now 🙂

 

 let spritesheetPropsTexture = PIXI.Texture.from(this.asset.get("images/props.png"));
        let spritesheetPropsSprite = new PIXI.Sprite(spritesheetPropsTexture);
        this.mySheet = new PIXI.Spritesheet(spritesheetPropsSprite.texture.baseTexture, this.imagePropsJson);

        this.mySheet.parse((textures) => {
            let cheese = new PIXI.Sprite(this.mySheet.textures["antenne.png"]);
            cheese.x = 200;
            cheese.y = 200;
            this.scene.addChild(cheese);
        })

"this.asset.get" is just my own reference to files. The only thing i had to change was:

this.mySheet.parse((textures) => {

Her goes my spritesheets

})

 

Share this post


Link to post
Share on other sites

You dont have to remember that, its better to clone pixi sources, open them in separate IDE window and search for classes when you use them. That way you can find something like that https://github.com/pixijs/pixi.js/blob/4590b0b5ed156c731e4041940c587d78480d7e84/packages/spritesheet/src/Spritesheet.ts#L203  , modify your code and forget about it :)

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.