kei Posted August 28, 2014 Share Posted August 28, 2014 Hi there, i'm using Phaser for the first time and i have some problems understanding how it works. I'm developing a platformer in which the main character plays a different animation for each action (run, jump, etc). When a new animation is played the width/height values of the sprite body are not updated, instead the values of the first animation added are maintained. This is a problem when the frame's width/height of each animation are not the same. In my case the frame's height of an animation is less than the previous one, so it looks like the character is floating. Am i using Phaser the wrong way? Is there any workaround to fix this other than change the values manually? Link to comment Share on other sites More sharing options...
JUL Posted August 29, 2014 Share Posted August 29, 2014 i'm using Phaser for the first time...Am i using Phaser the wrong way? Probably. //load a sprite sheet where each frames are 32x32 pixelsgame.load.spritesheet('P1SpriteSheet', 'src/assets/img/P1SpriteSheet.png', 32, 32); //Then create the sprite, called obj for example var obj=game.add.sprite(0,0, 'P1SpriteSheet');obj.animations.add('run', [1, 2, 3, 4, 5, 6], 10, true); game.physics.enable(obj, Phaser.Physics.ARCADE);obj.enableBody = true;obj.body.allowGravity=true; obj.body.width=12;obj.body.height=24;obj.anchor.setTo(0.5, 1); //optional stuffs obj.body.collideWorldBounds = true; obj.body.maxVelocity.y=500;obj.body.fixedRotation = true;obj.body.linearDamping = 0; obj.play('run'); Link to comment Share on other sites More sharing options...
crysfel Posted August 29, 2014 Share Posted August 29, 2014 I think you should change the size of the body and leave the animation frames as they originally are, same with/height for all of them, Im not sure if you can change the size of the sprite for each animation. http://docs.phaser.io/Phaser.Physics.Arcade.Body.html#setSize Regards Link to comment Share on other sites More sharing options...
ZoomBox Posted August 29, 2014 Share Posted August 29, 2014 The quick-fix would be to do:mySprite.anchor.y=1; (before enabling physics)I think it would do the trick but it could be annoying for you later. Link to comment Share on other sites More sharing options...
kei Posted August 29, 2014 Author Share Posted August 29, 2014 The quick-fix would be to do:mySprite.anchor.y=1; (before enabling physics)I think it would do the trick but it could be annoying for you later.Thanks, that's what i was looking for! Link to comment Share on other sites More sharing options...
Recommended Posts