sidneywidmer Posted May 18, 2014 Share Posted May 18, 2014 Hey everyone, Is it possible to scale a sprite but leave its body as is? I have the following code:var tween = this.game.add.tween(this.scale).to({x: 0.7, y: 0.7}, 600, Phaser.Easing.Linear.None, true, 0, Number.MAX_VALUE, true);With this tween i also change the body of the sprite and not just the underlying texture/image. Link to comment Share on other sites More sharing options...
sidneywidmer Posted May 21, 2014 Author Share Posted May 21, 2014 Is this really not possible? I'm fighting with this for several days now and couldn't figure anything out yet... Can't I somehow access the underlying PIXI texture and change that? Link to comment Share on other sites More sharing options...
Zaidar Posted May 21, 2014 Share Posted May 21, 2014 What if you use setSize() on the body ?It works with the Arcade physics btw.http://docs.phaser.io/Phaser.Physics.Arcade.Body.html#setSize Link to comment Share on other sites More sharing options...
sidneywidmer Posted May 23, 2014 Author Share Posted May 23, 2014 Basically I need the exact opposite of this. I don't want to scale the body, I want to scale the graphic. So let's say the physics body is 30x30px, then the image inside of it should only be 15x15px Link to comment Share on other sites More sharing options...
lewster32 Posted May 23, 2014 Share Posted May 23, 2014 setSize can make the body bigger or smaller. If your sprite is anchored to the center (sprite.anchor.set(0.5)) then you can make the body twice as large by doing:sprite.body.setSize(sprite.width * 2, sprite.height * 2, 0, 0);Whereas if you want it to be twice as small you'd do:sprite.body.setSize(sprite.width * 0.5, sprite.height * 0.5, 0, 0);If the anchor is not central, then the second two parameters would have to be set accordingly to adjust the offset on the x and y axes. Also, I believe some of the static functions in the Phaser.Rectangle object can be applied to the body, such as Phaser.Rectangle.inflate, as they just alter the x, y, width and height - all of which are valid properties on body. This may cause type errors in TypeScript however. Link to comment Share on other sites More sharing options...
Recommended Posts