Skip to content

Instantly share code, notes, and snippets.

Last active May 28, 2019
What would you like to do?
Function to get a texture from Pixi's resource loader
// "app" is an instance of PixiJS Application
export default app => (filename) => {
const {
} = app.loader;
const texture = Object
.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];
// Example usage, assuming you have an image called 'player':
// const texture = getTexture(‘player’)
// const sprite = new Pixi.Sprite(texture)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment