Jump to content

Create an array of sprites with Pixi load?


Recommended Posts

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:


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);


Link to comment
Share on other sites

something like that

function Wrapper(loader) {
    var keys = [];

    this.add = function (key, resourcePath) {
        loader.add(key, resourcePath);
        return loader;

    this.createTexturesArray = function () {
        var textures = [];
        keys.forEach(function (key) {
        return textures;


var wrapper = new Wrapper(PIXI.loader);

    .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) {



Link to comment
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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...