Jump to content

No collision detected on sprite sides


Alwin
 Share

Recommended Posts

Hi guys !

 

I am trying to create a classical 2D platform game (They are so great, aren't they?) with Phaser that i discovered recently. I certainly explain why i am not able to explain the reason of this strange behavior.

 

My problem is that when i am moving my character, it only collides with the top and down sides of my blocks.

Is there any reason for that behavior ?

 

Here is my global configuration:

 // Physics configurationthis.phaserInstance.physics.startSystem(Phaser.Physics.ARCADE);this.phaserInstance.physics.arcade.gravity.y = 300;// Setting the world boundariesthis.phaserInstance.world.setBounds(0,0, 2800, 1400);// Adding the blue backgroundthis.phaserInstance.add.tileSprite(0,0, 2800 , 1400,'background');this.phaserInstance.camera.y = 1000;

Then i add my sprites:

box = this.phaserInstance.add.sprite(200, 1300, 'tiles', 'box');this.phaserInstance.physics.enable(box, Phaser.Physics.ARCADE);box.body.collideWorldBounds = true;box.body.allowGravity = false;box.body.immovable = true;me = this.phaserInstance.add.sprite(200, 1000, 'player1');this.phaserInstance.physics.enable(me, Phaser.Physics.ARCADE);me.body.collideWorldBounds = true;console.log(me.body.checkCollision.right);console.log(box.body.checkCollision.right);cursors = this.game.input.keyboard.createCursorKeys();

Finally, i add my collision detection in the 'update' function

update: function(){	this.phaserInstance.physics.arcade.collide(me, box);	if(cursors.right.isDown) {		me.body.x += 5;	}	if(cursors.left.isDown) {		me.body.x -= 5;	}},

Any thoughts ?

Thanks !

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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