0

I'm trying to move a PictureBox diagonally in a game I'm making.

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);
        }
    }
}

I'm using a timer to move the bullets. What I would like to do is move the bullet 5 pixel per tick (which is 1 millisecond). if you look at the attached picture below, what i'm trying to do is move those yellow bullet shaped in the corners diagonally.(i only have them there so i can represent where they spawn in). [1]: https://i.stack.imgur.com/wQc5l.png

Fidelio
  • 71
  • 3
  • The Timer resolution is 15-25 ms. Why don't you show the Tick event? It would help to use floats to keep track of the position, even if you need to cast them to int for setting the position. – TaW Aug 13 '15 at 07:23

2 Answers2

1

Try to move in one go:

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

in order to prevent jitting (i.e. unwanted redrawing - first redrawing after X coordinate is changed, than after Y)

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0

I'm not sure I understand your question, but if you are moving it 1 pixel in your code, to move it 5 pixels, you'd only need to do:

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

If that's not what you are looking for, please be more clear in your question

Jcl
  • 27,696
  • 5
  • 61
  • 92