【问题标题】:AS3 collision detection for infinite running game无限运行游戏的 AS3 碰撞检测
【发布时间】:2012-12-25 22:16:48
【问题描述】:

我是 AS3 的新手,希望在碰撞检测方面获得一些帮助。我目前正在制作一个与机器人独角兽攻击类似概念的游戏(连续,“无限”,关卡);横向滚动运行平台游戏。我找到了 0 个关于连续/循环运行风格平台游戏的教程,所以我来了!我有一个静止的玩家,平台被脚本化为移动到屏幕左侧以获得滚动/运行效果。我在舞台上有三个平台实例,但是玩家只会对与其中一个的碰撞做出反应。正在从所有平台检测到碰撞。

下面的代码用于在我的游戏循环函数中执行的碰撞​​。帮助将不胜感激! :D 谢谢。

           for (var i = 0; i < numChildren; i++)
        {
            if (getChildAt(i) is Platform)
            {
                var platformHolder = getChildAt(i) as Platform


                if (platformHolder.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true))
                {
                    trace("left hit")
                    leftBumping = true;
                }

                else

                {
                    leftBumping = false
                }

                if(platformHolder.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true))
                {
                    trace("right hit");
                    rightBumping = true;
                }
                else
                {
                    rightBumping = false;
                }

                if(platformHolder.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true))
                {
                    trace("Up hit");
                    upBumping = true;
                }
                else
                {
                    upBumping = false;
                }

                if(platformHolder.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true))
                {
                    trace("down hit");
                    downBumping = true;
                }
                else
                {
                    downBumping = false;
                }
                }

            }


        if(leftBumping)
        {
            if(xSpeed < 0)
            {
                xSpeed *= -0.5;
            }
        }

        if(rightBumping)
        {
            if(xSpeed > 0)
            {
                xSpeed *= -0.5;
            }
        }

        if(upBumping)
        {
            if(ySpeed < 0)
            {
                ySpeed *= -0.5;
            }
        }

        if(downBumping)
        {
            if(ySpeed > 0)
            {
                ySpeed *= -0.5;
            }
        }
        else
        {
            //if not touching the floor
            ySpeed += gravityConstant;
        }

【问题讨论】:

  • 你需要让你的问题比“我需要帮助”更具体。特别是什么坏了?这是一个问答网站,因此您的问题应该针对特定问题,而不是一般的帮助需求。
  • 无论如何,您的实际问题与this question 中的相同:每当平台不与播放器发生碰撞时,您将相应的标志重置为false,甚至如果之前是真的。解决办法是不要那样做;只需在循环之前将所有标志设置为false,然后仅在检测到碰撞时更改它们。

标签: actionscript collision-detection


【解决方案1】:
If(platformholder[i].hitTestObject(player))

添加我制作循环的真正原因

【讨论】:

    猜你喜欢
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多