Saturday, April 26, 2014

MelonJS collision with entities not working

I recently started playing around with MelonJS to create a simple platformer game. Quickly I ran into an issue where my character was not colliding with other entities. The strange this is that the character was respecting the solid objects specified in the collision layer of the TMX map. This lead to several problems like not being able to pick up coins and being unable to change to the next level. The problem turned out to be that in the player's update method, I was not telling the game engine to process these types of collisions.
    update: function(dt) {

        // check entity collision
        var res = me.game.world.collide(this);
 
        // check & update player movement
        this.updateMovement();

        ...
    },
The key is to make sure you have the me.game.world.collide(this) call.

No comments:

Post a Comment