I am making a game in XNA where a player moves around the screen 'collecting' kiwis (the animal, not the fruit). I want to make it so that when the player collides with a kiwi, the kiwi sprite disappears.
So far, I can only make all the kiwis disappear when a collision occurs. I only want each individual sprite to disappear in a collision. I am using the same sprite for all the kiwis.
Here is the collision function:
void Collision()
{
if (!isCollected)
{
foreach (Rectangle kiwi in kiwiRectangle)
{
if (kiwi.Intersects(Sprite.spriteDestinationRectangle))
{
isCollected = true;
}
}
}
}
kiwiRectangle is an array holding rectangles that are created around each of the kiwi sprites that is drawn.
And then in the Draw() function:
if (!isCollected)
{
foreach (Vector2 position in kiwiPosition)
{
spriteBatch.Draw(kiwi, position, Color.White);
}
}