碰撞p2物理不起作用

时间:2016-05-03 17:11:41

标签: javascript phaser-framework

我正试图让Phaser中的碰撞工作。 我正在使用p2物理,我希望在玩家敲门时调用一个函数:

    //Load player                        
    playerSprite = this.game.add.sprite(50, 900, 'player-front');
    player = new Player(playerSprite);

    //1
    //Enter door 
    door = this.game.add.sprite(350, 865, 'player-back');

然后我开始了物理学:

 this.game.physics.startSystem(Phaser.Physics.P2JS);
    //Setting up witch tiles needs colliders
    map.setCollision(261, true, 'Collisions');
    this.game.physics.p2.convertTilemap(map, 'Collisions');
    this.game.physics.p2.enable([player.sprite, door], false);
    player.sprite.body.fixedRotation = true;

    //Physics engine create collision bodies from the tiles

    this.game.physics.arcade.enable(map);
    this.game.physics.setBoundsToWorld();
    //
    this.game.physics.p2.setImpactEvents(true);

    this.game.physics.p2.updateBoundsCollisionGroup();

然后我制作2个变量并设置与玩家的碰撞

    var playerCollisionGroup = this.game.physics.p2.createCollisionGroup();
    var doorCollisionGroup = this.game.physics.p2.createCollisionGroup();

    door.physicsBodyType = Phaser.Physics.P2JS;

    door.body.setCollisionGroup(doorCollisionGroup);

    door.body.collides(playerCollisionGroup);

    player.sprite.body.setCollisionGroup(playerCollisionGroup);

    player.sprite.body.collides(doorCollisionGroup, this.hitDoor, this);

hitDoor函数如下所示:

 hitDoor: function(body1, body2){
    console.log("Collision works");
},

我不知道为什么它现在正在运作。 谁能看到问题呢? TY

0 个答案:

没有答案