scutajar 1 Report post Posted September 26, 2013 Just a quick question regarding changing a sprite's graphic while the game is running.Before, this was done using the sprite's function loadGraphic. This doesn't exist anymore, and unless I'm missing something, I haven't found a suitable replacement in either Phaser.Sprite or PIXI.Sprite.Any help would be appreciated Quote Share this post Link to post Share on other sites
scutajar 1 Report post Posted September 27, 2013 I've managed a workaround by killing the existing sprite and creating a new sprite with the graphic I needed. Not exactly what I had in mine, but it works for now. Quote Share this post Link to post Share on other sites
Squize 1 Report post Posted September 27, 2013 Yeah I was wondering if there's a gotoAndStop("frame") equivalent, and if it exists on Sprites or via the Animation class. Squize. Quote Share this post Link to post Share on other sites
hackenstein 15 Report post Posted September 28, 2013 You could use one sprite sheet and just change the current animation Quote Share this post Link to post Share on other sites
onedayitwillmake 8 Report post Posted October 11, 2013 If PIXI was accessible, it seems you would simply be able to saysprite.setTexture( PIXI.TextureCache[key] );But phaser does not expose the PIXI object. In a game I'm working on, I have to change the 'polarity' of an object, and it's represented by a different sprite.And this can happen many times over and over, it'd be much easier to simply set the texture than to destroy and recreate a new sprite each time I wanted to do this. Seems like a reasonable request Quote Share this post Link to post Share on other sites
Hsaka 33 Report post Posted October 11, 2013 This is in the dev branch.https://github.com/photonstorm/phaser/commit/a7230aa769371c8f588893a2fb0517620e63f16f Quote Share this post Link to post Share on other sites
onedayitwillmake 8 Report post Posted October 11, 2013 Oh, awesome! Quote Share this post Link to post Share on other sites
InsaneHero 17 Report post Posted October 11, 2013 I don't have that branch checked out... anyone got comments on the efficiency of this approach? (Is it light and suitable for frequent use, or cpu/gpu intensive and only good for between levels?) Quote Share this post Link to post Share on other sites
turnA 21 Report post Posted October 11, 2013 I think loading a new graphic/change texture just to change sprite image is a bit overkill.Like hackenstein said, you can load spritesheet image and change the frame of the Sprite as you need.game.load.spritesheet('character', 'character.png', 60, 60);var character = game.add.sprite(0, 0, 'character');character.frame = 0; //Character idle imagecharacter.frame = 1; //Character jump image 2 tidelake and jdnichollsc reacted to this Quote Share this post Link to post Share on other sites
Mike 56 Report post Posted October 11, 2013 In addition here is how i change the sprite size:game.load.atlas('tiles', 'assets/textureAtlas/breakout.png', 'assets/textureAtlas/breakout.json');paddle = game.add.sprite(game.world.centerX, game.world.height - 48, 'tiles', 'paddle_big.png');and then: if(isPaddleNerfed) { paddle.frameName = "paddle_small.png"; //paddle.animations.play('paddle_small', 10, true); } else { paddle.frameName = "paddle_big.png"; //paddle.animations.play('paddle_big', 10, true); } this way you can even change a sprite animation and not only between two frames... and it depends on the need which is better Quote Share this post Link to post Share on other sites
onedayitwillmake 8 Report post Posted October 11, 2013 I think loading a new graphic/change texture just to change sprite image is a bit overkill.Like hackenstein said, you can load spritesheet image and change the frame of the Sprite as you need.game.load.spritesheet('character', 'character.png', 60, 60);var character = game.add.sprite(0, 0, 'character');character.frame = 0; //Character idle imagecharacter.frame = 1; //Character jump image I disagree, since the texture is basically a reference to a PIXI.Texture instance changing which reference any sprite is using doesn't seem like it would be particularly intensive Quote Share this post Link to post Share on other sites