Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I need to list all the files in the res folder from a JavaScript script in cocos2d-x. What would be the most efficient way to do this?

To keep compatibility with Cocos2d-html5 a JavaScript-only solution is most desirable.

share|improve this question

2 Answers 2

Javascript doesn't have access to the filesystem. This is for security purposes.

However, HTML5 does allow access to a sandbox filesystem. Cocos2D has an implementation of this sandbox access, but it doesn't appear to be official support. It's not too likely that utilizing this sandbox will be something that's cross platform. In this situation, you'll likely have to create platform specific code.

share|improve this answer
    
Currently I know more or less the names of the files I need to access so I keep fishing but this solution generates a lot of errors and is definitely not good for production code... –  Coyote Dec 19 '13 at 20:41

Not sure if this will help, but in the following this file: http://cocos2djs.org/demos/tile-maps I found this construct:

var map = new TMXTiledMap(
    { file: path.join(__dirname, '../resources/TileMaps/iso-test.tmx')})

The github site also has tutorials on using javascript for cocos2d

share|improve this answer
    
Unfortunately it doesn't help. I'm looking for an API to list available files in a folder. I can read any file y name, there is no problem with that. –  Coyote Dec 21 '13 at 10:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.