Jump to content

Sprite on Sprite


Heppell08
 Share

Recommended Posts

I have seen a post on this and it said to create the player as a group and load on sprites on sprites like that. I figured if i have a group called weapons, load my weapons in that group and give it the player as the parent and they follow as they should. That's all fine for now but my issue is the lag. The gun seems to trail behind and not look like its stuck to the player. I was wondering if there was a way to create the visuals of the gun being stuck to the player with my weapon group and player parent set up?

My group looks like this so far:

weapons = game.add.group(player);    for(var k = 0; k < 1; k++)    {    gun1 = game.add.sprite(5, 5,'gun1');    gun1.scale.x = 0.35;    gun1.scale.y = 0.35;    }
Link to comment
Share on other sites

Fixed it.

 

Code: 

weapons = game.add.group(player);    for(var k = 0; k < 1; k++)    {    gun1 = weapons.create(5, 8,'gun1');    gun1.scale.x = 0.20;    gun1.scale.y = 0.20;    gun1.anchor.setTo(0.5, 0.5);    }

Then scaled the image with left/right:

if(cursors.left.isDown)	{		player.body.velocity.x = -150;        if(facing !== 'left')        {            gun1.scale.x *=-1;            facing = 'left';        }    }	else if (cursors.right.isDown)	{		player.body.velocity.x = 150;        if(facing !== 'right')        {            gun1.scale.x *=-1;            facing = 'right';        }    }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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