Jump to content

Collision between entity and map not working


Ansimuz
 Share

Recommended Posts

Hi,

 

I'm learning phaser and got this issue.

The collision between the  player  and the map is not working since I moved the player to its own file (player.js) as an object

Im calling this in the update function on the play.js

game.physics.arcade.collide(this.player.sprite, this.layer);

 

I'm creating the tile map in the play.js

createWorld: function () {

        this.map = game.add.tilemap('map');
        this.map.addTilesetImage('tileset');
        this.layer = this.map.createLayer('Tile Layer 1');
        this.layer.resizeWorld();
        this.map.setCollision(1);

    },

 

Here's the player.js file

function player() {

    this.preload = function () {

    };

    this.create = function () {
        this.sprite = game.add.sprite(game.width / 2, game.height / 2, 'atlas', 'player01');
        this.sprite.anchor.setTo(0.5, 0.5);
        game.physics.arcade.enable(this.sprite);
        this.sprite.body.gravity.y = 500;

        this.cursor = game.input.keyboard.createCursorKeys();

    };

    this.update = function () {

    };

}

 

Originally the collision worked well before putting the player in a different file, but I can't make the collision work now.

 

 

 

Link to comment
Share on other sites

Do you use console in Browser test?

 You can put "console.log("any info");" inside update function, it shows theposition where exist any error, when it doesn't print.

 

If it works before, you include any error, a position of code can be changed.

 

Excuse my poor english.

 

Link to comment
Share on other sites

17 hours ago, Kseiver said:

Do you use console in Browser test?

 You can put "console.log("any info");" inside update function, it shows theposition where exist any error, when it doesn't print.

 

If it works before, you include any error, a position of code can be changed.

 

Excuse my poor english.

 

It doesn't throw any error. It just doesn't collide. the player goes thorugh as it there was not floor while falling.

Link to comment
Share on other sites

Some errors doesn't display anything, just stops the execution of the code. When this occurs I only can discover the location of the problem with prints.

Do you have the old version?

If have, make the change and test for each step.

if don't, try to modify to back to correct stage, and try step by step. It's boring, but ... it is one way.

If you want me to test your code, post the URL.

 

Link to comment
Share on other sites

1 hour ago, Kseiver said:

Some errors doesn't display anything, just stops the execution of the code. When this occurs I only can discover the location of the problem with prints.

Do you have the old version?

If have, make the change and test for each step.

if don't, try to modify to back to correct stage, and try step by step. It's boring, but ... it is one way.

If you want me to test your code, post the URL.

 

Thanks Kseiver.

 

Here's the url of the buggy game. http://ansimuz.com/phaser/first-game/

 

 I cant see the issue. Seems like I'm not entering the parameters for  game.physics.arcade.collide Correctly.

game.physics.arcade.collide(this.player.sprite, this.layer);

 

Link to comment
Share on other sites

4 hours ago, samme said:

In `update` the `alive` test is wrong, it should be


player.sprite.alive

 

Ohh that solved the issue. It was a logic problem after all.

the game.physics.arcade.collide never executed because of the alive condition.

Thanks Samme.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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