dianxiangan32

A Problem about body

Recommended Posts

I am develop a multiplayer game. I come to a problem and I am really confused.

 

The game's url is:

 

http://floating-brook-7619.herokuapp.com/

 

control:up down left right space

 

the problem is ,when I press space.  the skill sprite appear at a wrong place although it change to the right position immediately. I don't know why, Please help me! I really need help!

 

HELP!HELP!

 

 

the code related is in line 135:

 

if(this.GAME.game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)&&this.role.longPaoXiao.exists==false){
this.role.longPaoXiao.reset(this.role.x,this.role.y);
this.role.longPaoXiao.play('do',8,false,true);
 
}
 
and in line 163:
 
util.createPlayer=function(x,y,img,frame,id,GAME){
var role=GAME.game.add.sprite(x,y,img,frame);
role.animations.add('right',[6,7,8],3,true);
role.animations.add('left',[3,4,5],3,true);
role.animations.add('up',[9,10,11],3,true);
role.animations.add('down',[0,1,2],3,true);
GAME.game.physics.enable(role,Phaser.Physics.ARCADE);
role.id=id;
role.scale={x:0.6,y:0.6};
role.anchor.x=0.5;
role.anchor.y=0.5;
 
 
role.longPaoXiao=GAME.game.add.sprite(x,y,'longpaoxiao',15);
role.longPaoXiao.scale={x:0.5,y:0.5};
role.longPaoXiao.anchor={x:0.5,y:0.5};
GAME.game.physics.enable(role.longPaoXiao,Phaser.Physics.ARCADE);
role.longPaoXiao.body.setSize(130,130);
role.longPaoXiao.kill();
role.longPaoXiao.animations.add('do',[15,16,17,18,19,20,21,22,23,24,25,26,27],8,false);
 
 
return role;
}

 

Share this post


Link to post
Share on other sites

Try this:

this.role.longPaoXiao.body.reset(this.role.x,this.role.y);

Resetting the sprite position while the body is influencing it will often lead to incorrect positioning, the item flying off the screen or other problems. When the body is in control of the sprite's positioning, you should be using body.reset, body.velocity and so on to move it. If you don't want the physics to influence the sprite's movement, you can set body.moves = false and then move the sprite as normal.

Share this post


Link to post
Share on other sites

Try this:

this.role.longPaoXiao.body.reset(this.role.x,this.role.y);

Resetting the sprite position while the body is influencing it will often lead to incorrect positioning, the item flying off the screen or other problems. When the body is in control of the sprite's positioning, you should be using body.reset, body.velocity and so on to move it. If you don't want the physics to influence the sprite's movement, you can set body.moves = false and then move the sprite as normal.

you are very kind. Thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.