Jump to content

Phaser problem while collision to the ledge


bilginhalil
 Share

Recommended Posts

Here is my preload function 

function preload() {	game.load.atlas('soldier1', 'assets/spritesheets/soldier4_full.png', 'assets/spritesheets/soldier4_full.json', Phaser.Loader.TEXTURE_ATLAS_JSON_HASH);	game.load.image('desert', 'assets/images/desert.png');	game.load.image('desert_ledge', 'assets/images/desert_ledge.png');} 

And this is create

function create() {	game.physics.startSystem(Phaser.Physics.ARCADE);	map = game.add.sprite(0, 0, 'desert');	//  The platforms group contains the ground and the 2 ledges we can jump on    platforms = game.add.group();	platforms.enableBody = true;	ledges = [		[0.5, 0.6, 70, 499],		[0.5, 0.6, 330, 499],		[0.5, 0.6, 600, 499],		[0.8, 0.6, 290, 274],		[0.5, 0.6, 150, 389],		[0.5, 0.6, 500, 389],		[0.5, 0.6, 500, 163],		[0.5, 0.6, 150, 163],	];	ledges.forEach(function(info){            var ledge = platforms.create(info[2], info[3], 'desert_ledge');	    ledge.body.immovable = true;	    ledge.scale.setTo(info[0], info[1]);	});	player = game.add.sprite(50, 150, 'soldier1');	player.anchor.setTo(.5, .5);	player.enableBody = true;	game.physics.arcade.enable(player);	//  Player physics properties. Give the little guy a slight bounce.	player.body.bounce.y = 0.2;	player.body.collideWorldBounds = false;	//player.body.setSize(player.body.width*0.7, player.body.height);	player.frameName = 'Idle__000.png';	setAnimations();	player.animations.play('walk');	player.body.gravity.y = 700;	cursors = game.input.keyboard.createCursorKeys();}

Finally here is update

function update() {	game.physics.arcade.collide(player, platforms, null, function(player, ledge){		if(cursors.down.isDown)		{			console.log('down');			return false;		}		if(player.body.velocity.y < 0)			return false;		return true;	}, this);	//  Reset the players velocity (movement)	player.body.velocity.x = 0;	if (cursors.left.isDown)	{		//  Move to the left		player.body.velocity.x = -150;		if(player.scale.x > 0)		{			player.scale.x *= -1;		}		if(player.body.touching.down)			player.animations.play('walk');	}	else if (cursors.right.isDown)	{		if(player.scale.x < 0)		{			player.scale.x *= -1;		}		//  Move to the right		player.body.velocity.x = 150;		if(player.body.touching.down)			player.animations.play('walk');	}	else	{		if(player.body.touching.down)			player.animations.play('idle');	}	if (cursors.up.isDown && player.body.touching.down)	{		player.body.velocity.y = -420;		player.animations.play('jump');	}}

Now When I start the game there is a space between player and ledge which i don't want to exist

p3us3.jpg

 

If i change spritesheet to another atlas space reduces

iyg860.png

 

I think this is not about atlas files because when i debug sprites it seems that character doesn't have any padding.

 

So how can i get rid of this problem ? Where am i missing ? 

 

Thanks in advance.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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