MelonJS-如何更改碰撞对象的位置(使用播放器实体推或拉)?

时间:2019-03-07 20:22:41

标签: javascript melonjs

我正开始使用MelonJS开发游戏,但我不知道如何制作可推送/可推送实体。

我很确定我采用的方法不正确,因为它无法检测到与碰撞元素的碰撞,从而使元素停止。

   // this function is called by the engine, when
// an object is touched by something (here collected)
onCollision: function (response, other) {
    // // do something when collected
    console.log(response, me.collision.types);
    switch (response.a.body.collisionType) {
        case me.collision.types.PLAYER_OBJECT:
            if (response.overlapV.x > -0) {
                console.log("pushed right");
                this.body.force = {
                    x: this.body.maxVel.x,
                    y: 0
                };
            } else if (response.overlapV.x < -0) {
                console.log("pushed left");
                this.body.force = {
                    x: -this.body.maxVel.x,
                    y: 0
                };
            } else if (response.overlapV.y > -0) {
                console.log("pushed down");
                this.body.force = {
                    x: 0,
                    y: this.body.maxVel.y
                };
            } else if (response.overlapV.y < -0) {
                this.body.force = {
                    x: 0,
                    y: -this.body.maxVel.y
                };
                console.log("pushed up");
                // response.b.body.force.y = 0;
                // response.b.body.force.x = -this.body.maxVel.y;
            } else {
                this.body.force = {
                    x: 0,
                    y: 0
                };
            }
            this.body.update();
            return false;
        default:
            return false;
    }
}

0 个答案:

没有答案