Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Phaser 2.0.2 + P2 Physics engine: collision detection/contact events


Vivern
 Share

Recommended Posts

Need to find a collision objects (contact events). Now is not displayed function alert ("Eahh, collision!"), Ie not processed by the collision.

What need to fix?

 

Link to Project (visual studio 2013 + type script): https://drive.google.com/file/d/0B1BUvrgMgztwbWYwSzRob2pOMk0/edit?usp=sharing

 

Code:

 

class Game {

    game: Phaser.Game;

    constructor() {
        this.game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: this.preload, create: this.create });
        this.game.input.maxPointers = 1;
        this.game.stage.disableVisibilityChange = true;
    }

    preload() {
        this.game.load.image('ShapeRect', 'assets/ShapeRect.png');
    }

    create() {
        this.game.physics.startSystem(Phaser.Physics.P2JS);
        this.game.physics.p2.gravity.y = 100;

        var sprite;
        var posY = 100;
        for (var i=1; i < 10; i++) {
            posY+= 100;
            sprite = this.game.add.sprite(350, posY, 'ShapeRect');
            sprite.anchor.setTo(0.5, 0.5);
            this.game.physics.p2.enable(sprite);
            sprite.body.onBeginContact.add(this.blockHit, this);
        }
    }

    blockHit(body, shapeA, shapeB, equations) {
        alert("Eahh, collision!");
    }
}

window.onload = () => {
    var game = new Game();
};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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