Jump to content

scaling a Sprite but not the body


sidneywidmer
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...