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

[feature request] Read a "folder" of resources #109

Closed
euan-reid opened this issue Sep 10, 2013 · 7 comments
Closed

[feature request] Read a "folder" of resources #109

euan-reid opened this issue Sep 10, 2013 · 7 comments

Comments

@euan-reid
Copy link

Roughly what it says. In a similar vein to the sound one, is there a way the devkit could allow us to read a folder of resources, so additional items can be added just to the folder with the code looping over its contents?

@bubbleboy14
Copy link
Contributor

Is this something you can't accomplish with the CACHE object?

http://doc.gameclosure.com/api/utilities.html#cache

You can use that to read files.

@euan-reid
Copy link
Author

It sort of ties in to #108. If the non-coders can just add files to
folders, that'd be preferable.

@euan-reid
Copy link
Author

Rereading these now I'm at work, doesn't the CACHE object only read JSON files? I was intending to use it for sounds and images.

@bubbleboy14
Copy link
Contributor

I see. So you want to use sounds and images in your game without explicitly referencing them in your code. You can do this with images using the SpriteView, which allows you to load up a whole collection of animations using a prefix. For instance:

var jerry = new SpriteView({
// ...
url: 'resources/images/jerry'
});

That SpriteView will find all the images that start with 'resources/images/jerry'. These may include:

'resources/images/jerry-run-01.png'
'resources/images/jerry-run-02.png'
'resources/images/jerry-run-03.png'
'resources/images/jerry-run-04.png'
'resources/images/jerry-idle-01.png'
'resources/images/jerry-idle-02.png'
'resources/images/jerry-idle-03.png'
'resources/images/jerry-idle-04.png'
'resources/images/jerry-complain-01.png'
'resources/images/jerry-complain-02.png'
'resources/images/jerry-complain-03.png'
'resources/images/jerry-complain-04.png'

Etc. It turns them into animations that you can trigger like this:

jerry.startAnimation('complain');

So your artists can drop new images into resources/images, and they'll end up in the game without you having to know/care about it.

No such mechanism exists for sounds. What would this API look like? The AudioManager initialization options include "files", an object mapping sound keys to definition objects. Perhaps we could add a new flag to this sound definition object, something like "autoFind". If this flag is set to true, maybe the AudioManager autopopulates the "sources" object with any sound file in the specified directory that matches "[sound_key]_[number].[sound_extension]".

We probably won't have time to look into something like this in the near future. If you want this feature, it may require some digging. We can give you some pointers on IRC (#gameclosure in freenode). Good luck, and don't forget to submit a pull request.

@euan-reid
Copy link
Author

Regarding images, it's not for animations, just static items (fruits in a picnic basket is the current instance, as an example). So there's a folder resources/default/foods/ (default is the theme pack - we've got multiple themes, but their internal structures are the same), in which are images titled 1, 2, 3...n. In the json description of the pack, it lists the number of images - it'd be nice to not have that necessary, and instead be able to iterate over the images in the folder much like I might with php's glob.

For sounds, something like what you described would seem a decent startpoint. I'm a little busy with work currently, but might be able to have a go at it in the next couple of weeks. I'll see if I can't catch catid or marbar online there.

ArnoVanDerVegt added a commit that referenced this issue Sep 13, 2013
mgh pushed a commit that referenced this issue Nov 14, 2013
@collingreen
Copy link
Contributor

Did you come up with a solution for this?

@euan-reid
Copy link
Author

Afraid not - from what I recall, initial investigation suggested it was beyond the scope of just a plugin, so we decided to just stick with including the relevant number in the json.

@jwilm jwilm closed this as completed Feb 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants