I created a 2D tile-based jump and run game for Windows Phone and I want to draw a shadow under the character. How can I do that? The shadow must also be drawn on the tiles if the character jumps. The character and the tiles are rectangles.
How can I draw a shadow under my character?
The shadow should look similar to the shadows in this picture:
UPDATE: I tried to solve the problem like described in Gamefreak0's answer, but it's not working. I created a ShadowChecker object and I check in a foreach-loop if it collides with a platform. If it collides, the variable ShadowPosition gets changed. But it's not working correctly. I made a picture, and in this picture you see that the shadow isn't on a platform. Why is the shadow not getting drawn on the pink platform?
The character(black rectangle) is above the pink platform, so the shadow should be on the pink platform.
I update the shadow's position with this code:
protected override void Update(GameTime gameTime)
{
Rectangle CollisionRect = new Rectangle(-1000, -1000, 0, 0);
ShadowChecker = CharacterRect;
//FloorRect is the brown rectangle at the bottom. There is no other platform under the FloorRect.
while ((CollisionRect.Height == 0) && (ShadowChecker.Bottom <= (FloorRect.Y + FloorRect.Height / 2)))
{
ShadowChecker.Y += 1;
foreach (Rectangle r in PlatformRectangles)
{
if (ShadowChecker.Intersects(r))
{
CollisionRect = r;
break;
}
}
}
if (CollisionRect.Height != 0)
{
// Draw the shadow on this position
ShadowPosition = new Vector2(CharacterRect.X, CollisionRect.Y - CollisionRect.Height / 2);
}
base.Update(gameTime);
}