Skip to content

Instantly share code, notes, and snippets.

@sajmoni
Last active May 28, 2019 21:16
Show Gist options
  • Select an option

  • Save sajmoni/300d65e73ff8cc658ffdfb257b0722aa to your computer and use it in GitHub Desktop.

Select an option

Save sajmoni/300d65e73ff8cc658ffdfb257b0722aa to your computer and use it in GitHub Desktop.

Revisions

  1. sajmoni revised this gist May 28, 2019. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion getTexture.js
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,9 @@ export default app => (filename) => {
    if (!texture) throw new Error(`Texture "${filename}" not found.`);

    return texture[1];
    };
    };

    // Example usage, assuming you have an image called 'player':

    // const texture = getTexture(‘player’)
    // const sprite = new Pixi.Sprite(texture)
  2. sajmoni created this gist May 28, 2019.
    16 changes: 16 additions & 0 deletions getTexture.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // "app" is an instance of PixiJS Application
    export default app => (filename) => {
    const {
    resources,
    } = app.loader;

    const texture = Object
    .values(resources)
    .filter(resource => resource.textures)
    .flatMap(resource => Object.entries(resource.textures))
    .find(([key]) => key === `${filename}.png`);

    if (!texture) throw new Error(`Texture "${filename}" not found.`);

    return texture[1];
    };