【问题标题】:intersection is not happening sometimes有时不会发生交叉路口
【发布时间】:2014-04-05 20:40:00
【问题描述】:

我正在使用以下代码,其中 samosarect 是一个以一定速度从右到左的对象(假设每个循环 10 像素),舌头矩形是我的玩家的舌头,宽度增加到 200,然后再次减小到 0。只有舌头当舌头为真时增加,当我按下射击按钮时,舌头布尔值变为真。所以我的问题有时是我的玩家(舌头)不吃(不与 samosarect 相交)samosa(我用我的眼睛看着矩形相交但我的代码没有得到那个),有时它(与适当的动画相交)吃samosa没有任何问题。

if (Texture.samosarect.Contains(Texture.tonguerect) ||      Texture.tonguerect.Intersects(Texture.samosarect) && tongue)
            {
            Texture.tonguerect.Y = -50;
            System.Diagnostics.Debug.WriteLine("eated samosaaa");
            Texture.samosarect.X = -400;
            eateds = true;
            jumpframe = 17;
            tonguereached = true;
            caught = true;
            if (MainPage.togkey == 1)
                eateffect.Play();

            if (!catchedd)
            {
                score += 30; catched++; catchedd = true;
                showpoint = true;

            }
            else { catchedd = false; }

        }

【问题讨论】:

    标签: windows-phone-7 xna-4.0


    【解决方案1】:

    对于一般情况,thisthis 可以帮助您。

    算法描述here

    如果要准确谈论 xna,请查看here

    if (ballRect.Intersects(bat1Rect))
    {
        ballVelo.X = Math.Abs(ballVelo.X) * -1;
    }
    
    if (ballRect.Intersects(bat2Rect))
    {
        ballVelo.X = Math.Abs(ballVelo.X);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      • 2019-04-12
      • 2017-02-14
      • 2021-06-15
      相关资源
      最近更新 更多