rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
459 stars 50 forks source link

Creating hierarchy of assets instead of string key #23

Closed andreasmcdermott closed 8 years ago

andreasmcdermott commented 8 years ago

Would it be possible to add an option for loading assets into a hierarchy instead of the current solution?

Loading: this.loadImages('group/a', 'group/b', 'othergroup/c');

Using the assets currently: this.drawImage(this.images['group/a'], ..);

What I'd prefer: this.drawImage(this.images.group.a, ..);

RoryDuncan commented 8 years ago

+1 to this idea,

If you wanna accomplish it outside of the framework you can: Load images as full paths, "some/path/to/image", after all images are loaded, iterate over the images and 'expand' all images into the desired heirarchy using a function like this

rezoner commented 8 years ago

I've pushed r8 where "path/to/something" expands into path.to.something - please test it out

andreasmcdermott commented 8 years ago

Wow, that was quick. I tested it out and it works well for me. I now have both the 'group/img' and group.img.

rezoner commented 8 years ago

I do not want to get rid of "path/to/image" string yet as it would break the compatibility for many users. The caveat is that there are some edge cases like naming the image same as folder but I hope nobody does that. ;)