Jump to content

Can't scale sprite body using tween


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:


Thanks again for all the help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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