Todek Posted November 17, 2017 Share Posted November 17, 2017 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. Link to comment Share on other sites More sharing options...
samme Posted November 19, 2017 Share Posted November 19, 2017 Don't change the JSON data. Use sprite.scale, sprite.width, or sprite.height. http://phaser.io/examples/v2/category/arcade-physics Todek 1 Link to comment Share on other sites More sharing options...
Todek Posted November 20, 2017 Author Share Posted November 20, 2017 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 More sharing options...
samme Posted November 20, 2017 Share Posted November 20, 2017 You don't have to resize the body after scaling the sprite, that happens automatically: examples/v2/arcade-physics/body-scale You only need to do it to if you want a bounding box different from the sprite texture frame. Link to comment Share on other sites More sharing options...
Todek Posted November 21, 2017 Author Share Posted November 21, 2017 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 More sharing options...
samid737 Posted November 21, 2017 Share Posted November 21, 2017 Does sprite.width change the physics body size? You could try setSize when switching animation frames if you know each frame size. EDIT: nvm sprite.width or height does change the body size. Maybe the problem is in the spritesheet: Link to comment Share on other sites More sharing options...
Todek Posted November 23, 2017 Author Share Posted November 23, 2017 (edited) 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 November 23, 2017 by Todek SOLVED Link to comment Share on other sites More sharing options...
Recommended Posts