runeater Posted May 17, 2017 Share Posted May 17, 2017 I'm working on a small card game and I'd like to make an array of sprites to make the code more readable. What I mean is I have hearts,spades,clubs and diamonds and I'd like each to be its own array when I load my images from my assets. Below is similar to what I have: PIXI.Loader .add("hearts10","hearts10.png") .add("hearts9","hearts9.png") ... .load(start) I'd like to be able to access the cards via an array of arrays, sort of like: var current_card = new Sprite(resources.cards.hearts.10.texture); Quote Link to comment Share on other sites More sharing options...
xerver Posted May 17, 2017 Share Posted May 17, 2017 You can extract them from the resources object and put them into any structure you want. The resources object is simply an object with string keys and resources as values. Quote Link to comment Share on other sites More sharing options...
runeater Posted May 17, 2017 Author Share Posted May 17, 2017 I just want to be able to load them into my resources object as an array, is this possible? Quote Link to comment Share on other sites More sharing options...
evdokim Posted May 18, 2017 Share Posted May 18, 2017 something like that function Wrapper(loader) { var keys = []; this.add = function (key, resourcePath) { keys.push(key); loader.add(key, resourcePath); return loader; }; this.createTexturesArray = function () { var textures = []; keys.forEach(function (key) { textures.push(PIXI.utils.TextureCache[key]); }); return textures; }; } var wrapper = new Wrapper(PIXI.loader); wrapper .add("my-sprite1.png", "../res/my-sprite1.png") .add("my-sprite2.png", "../res/my-sprite2.png") .add("my-sprite3.png", "../res/my-sprite3.png") .add("my-sprite4.png", "../res/my-sprite4.png") .load(function () { var texturesArray = wrapper.createTexturesArray(); texturesArray.forEach(function (texture) { console.info(texture); }); }); Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 18, 2017 Share Posted May 18, 2017 Why do you need texture cache there? You have loader already Quote Link to comment Share on other sites More sharing options...
tywang2006 Posted May 18, 2017 Share Posted May 18, 2017 It is weird to use cache when using loader at same time, why not do sprite sheet, dont try to load mutli png files for a game development, which will make you trouble to manage all assets Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.