lewster32 Posted May 6, 2014 Share Posted May 6, 2014 I'm trying to put together an effect in a game where every sprite and image gets changed to a 'corrupted' version. I've created two texture atlases (with the keys 'sprites' and 'sprites-hacked'); both have identical data, but one has its source image modified. Without delving deep into the code, does anyone know if it's possible to quickly swap out all of the textures to use a new atlas? I've got so far as to change all non-animating sprites and images by simply using loadTexture, however if any of them are animating, they revert to the old atlas on the next frame. Main.prototype.setHacked = function (group, val) { var h = (val === true) ? '-hacked' : ''; for (var i = 0, len = group.children.length; i < len; i++) { if (group.children[i] instanceof Phaser.Sprite || group.children[i] instanceof Phaser.Image || group.children[i] instanceof Phaser.TileSprite) { if (group.children[i].frameName) { group.children[i].loadTexture('sprites' + h, group.children[i].frameName || 0); } } else if (group.children[i] instanceof Phaser.Group) { this.setHacked(group.children[i], val); } } };Ideally, it'd be nice if there was something I could use at runtime to simply update the source image for the atlas lookups, however from testing I can only manage to do that before I create any of the sprites - it has no effect after they've been created. If there is no current way to do this, I reckon would be a really handy feature to have to enable 'palette swap' type effects like you see in a lot of old games. Link to comment Share on other sites More sharing options...
lewster32 Posted May 6, 2014 Author Share Posted May 6, 2014 Looks like I may have figured this out (to a degree anyway). For sprites with animation, I've used the following (took a bit of digging into pixi's sources to find it):if (group.children[i].animations && group.children[i].animations.currentAnim) { group.children[i].texture.baseTexture.source = this.game.cache.getImage('sprites' + h);} Link to comment Share on other sites More sharing options...
Recommended Posts