Jump to content

Understanding Phaser, sprites and animations


kei
 Share

Recommended Posts

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

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 pixels

game.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

 Share

  • Recently Browsing   0 members

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