移动物体碰撞Phaser

时间:2016-05-09 19:50:37

标签: phaser-framework

我对移动物体的碰撞无效。我已经创建了一个演示,所以你可以看到它并查看我的问题所有代码和所有内容。

正如你可能看到的那样,我有两个街区从左到右,然后我有一个坦克射击子弹>我尝试了所有方向,我总是得到相同的结果,基本上我的碰撞只能工作块值的速度,在zip文件的例子中只能达到300px。根据块的速度,如果我将块速度更改为更大的数字,则碰撞将对相同的数字像素起作用。这真的很奇怪。

我想知道我是在做错事还是我的问题是什么?我将不胜感激,可以帮助我解决这个问题。感谢。

Demo source code

public void translate(Graphics g, GameContainer container, int delta) {
        g.translate(((container.getWidth() / 2) - this.x), ((container.getHeight() / 2) - this.y));
    }

    public void update(GameContainer container, int type){
        if (type == 0) {
            x = p.getX(); //p is the player
            y = p.getY();
        } else if (type == 1) {
            x = player.x;
            y = player.y;
        }

        if (offset) {
            if (this.x - container.getWidth() / 2 < offsetMin[0]) {
                x = offsetMin[0] + container.getWidth() / 2;
            } else if (this.x + container.getWidth() / 2 > offsetMax[0]) {
                x = offsetMax[0] - container.getWidth() / 2;
            }

            if (this.y - container.getHeight() / 2 < offsetMin[1]) {
                y = offsetMin[1] + container.getHeight() / 2;
            } else if (this.y + container.getHeight() > offsetMax[1]) {
                y = offsetMax[1] - container.getHeight() / 2;
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

代码肯定会有所帮助,但您实际上可以通过玩游戏了解正在发生的事情。

随着障碍的进行,如果你射击并击中最中心区域的右边缘,你实际上可以让子弹消失。

发生的事情是您正在检查项目符号和块之间是否发生冲突,但每次在左侧屏幕上添加新块时,块都会重新定义。

您可能想要做的是创建一个块池(例如bloquePool),几乎就像您在createBullets中使用子弹池所做的那样(您所谓的{ {1}})。

然后检查子弹组和块组之间的碰撞。

bullets

你应该将单个子弹和碰撞的单个块传递到this.game.physics.arcade.overlap( this.bullets, this.bloquePool, this.collisionBulletBloque, null, this ); ,这样你仍然可以像现在一样杀死子弹。

相关问题