Jump to content

Body vs Sprite (ARCADE physics)


Todek
 Share

Recommended Posts

Hello to everyone,

I am new to Phaser. These days I am studying the tutorials and I suddenly came across the many problems related to sprite of different dimensions.

So I am learning to use Texture Atlas.

I have create an animation with the related json file. All work just fine (visually).

Playing with the json file I am able to adjust the sprite width (green box) but not the body size (red box).

The ARCADE Physics has only ONE box size? Is there a way to automatically adjust the body size following the sprite size?

Or I must move on onto more complicated physics.

 

Thanks to enyone who can help me.

body-sprite.png

Link to comment
Share on other sites

Thank you for the tip!

so I can set the bodySize linking it to the sprite dimension.

I hope that if I put all in the update function I can resize the body for every frame of every animation, if I need it.

I'll give it a try as soon as I can

Link to comment
Share on other sites

I guess we are going in the right direction but I can't understand.

I do not neet to "scale" the sprite.

I have a Texture Atlas. and I need the body to follow the variation in dimension between each frame.

I think there is a way to do it automatically since Phaser support Atlas Texture. But in my code this did not happen.

So, reading your answers, I think that I can force this behavior using the height and the width.

In the attachment you can see the green box and the red box. The green one changes every frame. The red one is always with the dimension of the first frame.

 

Link to comment
Share on other sites

On 21/11/2017 at 7:01 PM, samid737 said:


EDIT:

nvm sprite.width or height does change the body size. Maybe the problem is in the spritesheet:

 

Are you sure? To test it I have:

-used another software to do create the Atlas Texture

-modified a Phaser example (http://phaser.io/examples/v2/animation/local-json-object) adding a Render function:

 

Quote

function render() {

    // Sprite debug info
    game.debug.spriteBounds(bot, "green", false);
    game.debug.body(bot, "red", false);

}

The body size remain fixed. The spriteBounds change every frame.

 

EDIT:

 

if I create this Update function it works perfectly.

Thank you both for the help!!!

 

Quote

function update(){
    bot.body.setSize(bot.width, bot.height);
    bot.animations.play('run', 2, true);
}

 

Edited by Todek
SOLVED
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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