Sturb Posted April 25, 2015 Share Posted April 25, 2015 I was wondering if there was a way to get the JSON data for an atlas after it is loaded. I want to make a utility function that will return an array of strings which are the frame names for any given animation. This way I don't need to list [ 'frame01, 'frame02', ..., 'frame99']. Basically you provide it a prefix and it searches the atlas data for all matching keys. Sort of the same way Starling's AssetManager handles it.Oh, and if there is already a way to do this, then pointing that out would help out too . Thanks. Link to comment Share on other sites More sharing options...
rich Posted April 26, 2015 Share Posted April 26, 2015 The atlas json isn't retained once the FrameData has been created, so at the moment there is no 'native' way to do it. I'd say either override Phaser.Cache.addTextureAtlas and then store the atlasData before passing it off to the parsers. Or load the json files using Loader.json instead and the textures with Loader.image and then just call Cache.addTextureAtlas directly, passing in both objects to it. Link to comment Share on other sites More sharing options...
Sturb Posted April 27, 2015 Author Share Posted April 27, 2015 Thanks! However I was able to figure something out with what was already provided in the framework. I was able to use this.game.cache.getFrameData, so get all the frames in an atlas which is perfectly fine. So if anyone is interested in something like this, here is my code. It's rather simple but comes in handy if your animations contains a large amount of frames.. (Note: I'm writing my game in Typescript, but you'll get the gist of it.Utility function: static getFrameKeys(prefix: string, frameData: Phaser.FrameData): Array<string> { // The return value; var out: Array<string> = []; // Search for matching frames. for (var i = 0; i < frameData.total; i++) { var name: string = frameData.getFrame(i).name; if (name.indexOf(prefix) == 0){ out.push(name); } } // Return the list of frame names matching the prefix. return out;}Usage:this.animations.add('flip', Utils.getFrameKeys('callLetterDisplay00', this.game.cache.getFrameData('gameAtlas1')), 30, true);So in this case I'm returning a rather large animation of roughly 80 frames. It's returning callLetterDisplay0001 to callLetterDisplay0080. indextwo 1 Link to comment Share on other sites More sharing options...
Recommended Posts