im trying to create simple pong game, and learning some XNA. im creating for each paddle 3 rectangles, who represnt the collision when the ball hit them, so i can dicide where to throw the ball back.
here is the function that i create the rectangles:
List<Rectangle> collisonRectanglesList = new List<Rectangle>(3);
private void creatCollisonRectangles()
{
smallPaddleWidth = collisionRect.Width;
smallPaddleHeight = collisionRect.Height / 3;
for (int i = 0; i < collisonRectanglesList.Count; i++)
{
if (collisonRectanglesList[i] != null)
collisonRectanglesList.RemoveAt(i);
}
collisonRectanglesList.Add(new Rectangle((int)position.X + smallPaddleWidth, (int)position.Y + smallPaddleHeight * 2, smallPaddleWidth, smallPaddleHeight));
collisonRectanglesList.Add(new Rectangle((int)position.X + smallPaddleWidth, (int)position.Y + smallPaddleHeight, smallPaddleWidth, smallPaddleHeight));
collisonRectanglesList.Add(new Rectangle((int)position.X + smallPaddleWidth, (int)position.Y , smallPaddleWidth, smallPaddleHeight));
}
now i want this to follow the paddle it self so i put this function in the update method and made a simple texture so i can draw them and see where they are on the screen.
my problem is that when i call the creatCollisonRectangles()
1 of the rectangles paint it self in the middle and not in the place it should be.
any idea why?
this is when im not calling it in the Update method:
and this when i do:
(sorry for my english)