JakeCake Posted October 21, 2015 Share Posted October 21, 2015 I am loading a bunch of texture atlases with many sprites in them, but now, for performance testing I would like to bulge some of these atlases together. Due to my automated gulp tasks this is no issues and only takes a couple of seconds, as to create the new textures, but still all my sprite creation use something like layer.foreground.create(x, y, 'enemies', 'enemy_pig'); which will no longer work if the atlas name has changed. If I combine the two atlases "enemies" and "pickups" into one, all these initialisations will fail. Since I have named the textures within each atlas with an unique key even across the atlases there will be no mixup. So my question is: How do I make phaser detect which atlas a texture-key is from, and is this a built in feature, since it seems obviously useful, or do I have to create my own implementation of detecting the atlas with a function like "findAtlas()" that searches the loaded atlases for a texture like: layer.foreground.create(x, y, findAtlas('enemy_pig').key, 'enemy_pig'); Thanks for any help Link to comment Share on other sites More sharing options...
chongdashu Posted October 21, 2015 Share Posted October 21, 2015 Pretty sure rolling your own solution is the way to go because I suspect Phaser doesn't support this custom functionality out of the box. I may be completely wrong though Link to comment Share on other sites More sharing options...
JakeCake Posted October 25, 2015 Author Share Posted October 25, 2015 For any future reference, here is the solution I ended up coding: Phaser.Cache.prototype.getAtlasForTexture = function(texturekey) { for(var key in game.cache._cache.image) { if(game.cache._cache.image[key].frameData.getFrameByName(texturekey)) { return game.cache._cache.image[key].key; } } return null; };It returns the key to the atlas containing the texture with the texture key given. So in all my sprite creation I do this:layer.foreground.create(x, y, game.cache.getAtlasForTexture("unique_key"), "unique_key");Since I'm prototyping, this is integrated right into the Phaser cache object. Link to comment Share on other sites More sharing options...
Recommended Posts