Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Loader Update #83

Closed
1 of 2 tasks
E-A-N opened this issue Nov 25, 2018 · 5 comments
Closed
1 of 2 tasks

Dynamic Loader Update #83

E-A-N opened this issue Nov 25, 2018 · 5 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@E-A-N
Copy link
Collaborator

E-A-N commented Nov 25, 2018

Lets make the loader better. Presently we're loading sprites by referencing the src then hardcoding the key in whatever module we're using them from. Ideally we want to load the reference to the src and key! and not hard code anything at all.
In the config, lets not store all of the sprite references in the loader attribute, instead lets make a default.resources attribute. The loader should handle the resources and that's it. Here's a code example:

config.js

config.default.graphicResources = {
    placeHolder: {
        src: "/location/ph.png",
        key: "placeHolder1"
    },
    character: {
        src:"/location/character.png",
        key:"character1"
    }
}

load.js

load.loadGraphics= (srcList) => {
    for (let i in srcList){
        let data = srcList[i];
        game.load.image(data.key, data.src);
    }
}

load.init = (data) => {
    const graphics = data.graphicResources || config.default.graphicResources;
    load.loadGraphics(graphics);
}

Now in any of our modules that need to create a sprite we can do this:

gameLoop.js

gameLoop.create = () => {
    let characterSpriteData = [
        config.default.graphicResources.character.key,
        config.default.graphicResources.character.src
    ];
    game.add.sprite(...characterSpriteData);
}

The tasks are:

  • update config model with something like config.default.graphicsResources
  • dynamically load graphics with helper function like loadGraphics above.
@E-A-N E-A-N added enhancement New feature or request help wanted Extra attention is needed labels Nov 25, 2018
@E-A-N
Copy link
Collaborator Author

E-A-N commented Nov 25, 2018

Phaser json loader may do this for us if someone wants to look up the docs. We just might have to change our model slightly.

Look up game.load.json in Phaser docs.

@E-A-N
Copy link
Collaborator Author

E-A-N commented Nov 25, 2018

Also, can't start this until @hal255 is finished with #76

@hal255
Copy link
Collaborator

hal255 commented Nov 25, 2018

@E-A-N Created pull request #86 for improvements to #76

@E-A-N E-A-N self-assigned this Nov 26, 2018
@E-A-N
Copy link
Collaborator Author

E-A-N commented Nov 26, 2018

I'll be working on this.

@E-A-N
Copy link
Collaborator Author

E-A-N commented Nov 26, 2018

Updated config spriteSrc/imageKey values to be consistent with all of the other values (src/key). This simplifies polymorphism and saves byte size. Byte size matters in this case, since resources will eventually be sent via network requests.

Won't be making a custom loader for reason stated in #91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants