如何对角移动图片框?

时间:2015-08-13 07:12:00

标签: c# animation

我试图在我正在制作的游戏中对角移动PictureBox

private void movebulletupright()
{
    //this part is mainly for checking the action[![enter image description here][1]][1]
    for (int k = bulletlistupright.Count - 1; k >= 0; k--)
    {
        bulletlistupright[k].Location.X++;
        bulletlistupright[k].Location.Y++;

        //This part is just basically meant to get rid of the bullet
        //when it reaches the end of the screen
        if (bulletlistupright[k].Left >= this.ClientSize.Height)
        {
            this.Controls.Remove(bulletlistupright[k]);

            bulletlistupright.RemoveAt(k);
        }
    }
}

我使用计时器来移动子弹。我想做的是每次打勾(1毫秒)移动子弹5个像素。如果你看下面的附图,我试图做的就是沿对角线移动那些角落形状的黄色子弹。(我只有它们,所以我可以代表它们产生的地方)。 [1]:MapReduce Patterns

2 个答案:

答案 0 :(得分:1)

尝试进入一次

  bulletlistupright[k].Location = new Point(
    bulletlistupright[k].Location.X + 5,  // 5 is X step
    bulletlistupright[k].Location.Y + 5); // 5 is Y step 

为了防止 jitting (即不需要的重绘 - 在X坐标改变之后首先重绘,而不是在Y之后重绘)

答案 1 :(得分:0)

我不确定我理解你的问题,但如果你在代码中移动1个像素,将它移动5个像素,你只需要这样做:

bulletlistupright[k].Location.X+=5;
bulletlistupright[k].Location.Y+=5;

如果这不是您想要的,请在您的问题中更清楚