Actionscript3简单的平台碰撞混乱

时间:2014-12-11 15:03:25

标签: actionscript-3 collision-detection flashdevelop

我正在制作2D平台游戏,我正在尝试向平台添加碰撞,这样当角色碰到它时就无法通过。我很难找到用于创建此冲突的语法。到目前为止,这就是我所拥有的。

此外,我仍然希望能够在if语句中使用hitTestObject。

感谢

public function platform1Collision():void
    {
        if (fireboy1.hitTestObject(Platform1))
        {
            //fireboy1 cannot pass through

        }
    }

1 个答案:

答案 0 :(得分:0)

您可能希望阻止fireboy1的{​​{1}}媒体资源延长y的{​​{1}}财产:

Platform1

注意:以上代码示例假定yfunction platform1Collision():void { if(fireboy1.hitTestObject(Platform1)) { if(fireboy1.y > Platform1.y) { fireboy1.y = Platform1.y + Platform1.height; } else { fireboy1.y = Platform1.y - fireboy1.height; } } } 的左上角方向。

已编辑:以上编辑过的代码允许fireboy1Platform1下方走,但不会通过它。

这是一个非常基本的例子,可以让您了解可以使用的逻辑类型。如果您想允许fireboy1从下面通过Platform1,则必须更新逻辑以允许此操作。例如,如果您取出fireboy1并且每次碰撞时自动将Platform1置于if/else之上,就会显示fireboy1正在跳转到Platform1当从下面接近时。