Jump to content

Can't scale sprite body using tween


aaronhampton
 Share

Recommended Posts

I am using a tween to scale a sprite from small to large, then yoyo-ing back to small. When the sprite scales, the body does not. I used setCircle to set a circle shaped body, if that makes a difference. I am also using P2 physics. Will I have to keep calling setCircle throughout the tween to make sure the body is the right size? Is there a way to scale the body through tweening or when the sprite is scaled?

Link to comment
Share on other sites

you need to scale the shape of the body.. you can acces the shape for example by putting it on a var on the first place..

myshape = player.body.seCircle(20);

but there are other ways too.. i guess something like

player.body.data.shapes[0]; should also work..

but.. there are other obstacles coming with shape changes.. it's not that easy

Link to comment
Share on other sites

Thanks! Both of those responses really helped me figure it out. My tween looks like this:

var speed = 1500;var multi = 3.5;var rad = sprite.body.data.shapes[0].radius;game.add.tween(sprite.scale).to(    {y: multi, x: multi}, speed, Phaser.Easing.Linear.None, true).repeat(Number.MAX_VALUE).yoyo(true);game.add.tween(sprite.body.data.shapes[0]).to(    {radius: rad * multi}, speed, Phaser.Easing.Linear.None, true).repeat(Number.MAX_VALUE).yoyo(true);

Then, in update I run the following to see the body update during debug:

sprite.body.debugBody.draw();

Thanks again for all the help!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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