Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的XNA游戏落后了?_C#_Xna - Fatal编程技术网

C# 为什么我的XNA游戏落后了?

C# 为什么我的XNA游戏落后了?,c#,xna,C#,Xna,在我们保存代码并提交给编程类之前,代码运行得非常好。我们相信我们有某种内存泄漏,但无法发现它。在保存代码之前,我们没有对代码进行任何更改,在保存之前,一切都正常,因此在保存代码时出现了一些问题。下面是我们更新方法中的所有代码。对于更新方法中的每一个困难,我们都有一个案例,我们认为这就是问题所在 //Easy game mode case GameState.Easy: //starts backgound music MediaPl

在我们保存代码并提交给编程类之前,代码运行得非常好。我们相信我们有某种内存泄漏,但无法发现它。在保存代码之前,我们没有对代码进行任何更改,在保存之前,一切都正常,因此在保存代码时出现了一些问题。下面是我们更新方法中的所有代码。对于更新方法中的每一个困难,我们都有一个案例,我们认为这就是问题所在

//Easy game mode
        case GameState.Easy:
            //starts backgound music
            MediaPlayer.Play(BackgroundMusic);
            this.IsMouseVisible = false;
            PlayerTwoSpeed = 5;

            if (HitCount == PointsToWin) PlayerOneWins();
            if (HitCountEnemy == PointsToWin) PlayerTwoWins();

            //getting the keyboard state, so input can be detected
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                if (POPBox.Y >= 373)
                {
                    POPBox.Y += 0;
                }
                else
                {
                    POPBox.Y += PlayersSpeed;
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                if (POPBox.Y <= 0)
                {
                    POPBox.Y += 0;
                }
                else
                {
                    POPBox.Y += -PlayersSpeed;
                }
            }
            // Ball limits

            if (BallBox.Y <= 0)
                VelocityY *= -1;
            if (BallBox.Y >= 463)
                VelocityY *= -1;

            //Collision Detection (Runs this code if it hits the player one's paddle)
            if (BallBox.Intersects(POPBox))
            {
                //Used to deflect in different directions for some veriety
                if (PlayersSpeed > 0)
                    VelocityY += 3;
                if (PlayersSpeed < 0)
                    VelocityY -= 3;
                VelocityX *= -1;
                ShockerGenerator();

                //Stopping the no slope bug. If it wants to bounce perfectly straight, it is slightly shifty to fix that error.

                if (VelocityY == 0)
                    VelocityY = VelocityY += 3;
                if (VelocityX == 0)
                    VelocityX = VelocityX += 3;

                //speed control

                if (VelocityX > 10)
                    VelocityX = 10;
                if (VelocityY > 10)
                    VelocityY = 10;
            }
            // Runs this code if the ball hits player two's paddle
            if (BallBox.Intersects(PTPBox))
            {
                VelocityX *= -1;
                if (VelocityY == 0)
                    VelocityY = VelocityY += 3;
                if (VelocityX == 0)
                    VelocityX = VelocityX += 3;
            }


            //Object a collision

            if (BallBox.Intersects(ShocObjectARectangle))
            {
                VelocityY *= -1;
            }
            if (BallBox.Intersects(ShocObjectBRectangle))
            {
                VelocityX *= -1;
            }


            // If Player One Loses

            if (BallBox.X >= 790)
            {
                PlayerOneLoses();
            }


            if (BallBox.X <= 0)
            {
                PlayerTwoLoses();

            }



            //Player Two's "AI" and limits

            if ((PTPBox.Y + 50) > BallBox.Y)
                PTPBox.Y += -PlayerTwoSpeed;
            if ((PTPBox.Y + 50) < BallBox.Y)
                PTPBox.Y += PlayerTwoSpeed;



            //Object A movement code

            ShocObjectARectangle.X += ObjectASpeed;
            if (ShocObjectARectangle.X <= 80)
                ObjectASpeed *= -1;
            else if (ShocObjectARectangle.X >= 600)
                ObjectASpeed *= -1;


            //Object B movement code

            ShocObjectBRectangle.Y += ObjectBSpeed;
            if (ShocObjectBRectangle.Y <= 0)
                ObjectBSpeed *= -1;
            else if (ShocObjectBRectangle.Y >= 415)
                ObjectBSpeed *= -1;


            // Ball Velocity

            BallBox.Y += -VelocityY;
            BallBox.X += VelocityX;
            break;
//简易游戏模式
案例游戏状态。简单:
//开始背景音乐
MediaPlayer.Play(背景音乐);
this.IsMouseVisible=false;
PlayerTwoSpeed=5;
如果(HitCount==PointsToWin)playerWins();
如果(HitCountForeign==PointsToWin)玩家获胜();
//获取键盘状态,以便可以检测输入
if(Keyboard.GetState().IsKeyDown(Keys.Down))
{
如果(POPBox.Y>=373)
{
POPBox.Y+=0;
}
其他的
{
POPBox.Y+=播放器速度;
}
}
if(Keyboard.GetState().IsKeyDown(Keys.Up))
{
如果(POPBox.Y=790)
{
playerone();
}

如果(BallBox.X在每次更新时,您都会在MediaPlayer中不断地将歌曲排队:

您需要将其移到update()方法之外


每次更新时,您都会在MediaPlayer中不断地将歌曲排队:

您需要将其移到update()方法之外


请把代码缩短到只包含相关部分…我不知道内存泄漏会在哪里。我假设它在其中一个案例中。我们编辑了主要帖子,只包含一个案例。你说的“保存”是什么意思它?这是一个很长的例子。@DB这可能是因为您在每次更新时都会在MediaPlayer中不断地将歌曲排队:MediaPlayer.Play(BackgroundMusic);请把代码缩短到只包含相关部分……我不知道内存泄漏会在哪里。我假设它在其中一个案例中。我们编辑了主要帖子,只包含一个案例。你说的“保存”是什么意思它?这是一个很长的例子。@DB这可能是因为您在每次更新时都会在MediaPlayer中不断地将歌曲排队:MediaPlayer.Play(BackgroundMusic);
MediaPlayer.Play(BackgroundMusic);