scutajar Posted September 26, 2013 Share 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 Link to comment Share on other sites More sharing options...
scutajar Posted September 27, 2013 Author Share 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. Link to comment Share on other sites More sharing options...
Squize Posted September 27, 2013 Share 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. Link to comment Share on other sites More sharing options...
hackenstein Posted September 28, 2013 Share Posted September 28, 2013 You could use one sprite sheet and just change the current animation Link to comment Share on other sites More sharing options...
onedayitwillmake Posted October 11, 2013 Share 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 Link to comment Share on other sites More sharing options...
Hsaka Posted October 11, 2013 Share Posted October 11, 2013 This is in the dev branch.https://github.com/photonstorm/phaser/commit/a7230aa769371c8f588893a2fb0517620e63f16f Link to comment Share on other sites More sharing options...
onedayitwillmake Posted October 11, 2013 Share Posted October 11, 2013 Oh, awesome! Link to comment Share on other sites More sharing options...
InsaneHero Posted October 11, 2013 Share 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?) Link to comment Share on other sites More sharing options...
turnA Posted October 11, 2013 Share 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 tidelake and jdnichollsc 2 Link to comment Share on other sites More sharing options...
Mike Posted October 11, 2013 Share 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 Link to comment Share on other sites More sharing options...
onedayitwillmake Posted October 11, 2013 Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts