I am having a bit of trouble with my collision detection. It only works correctly for the right side, meaning, if I enter the tile from any other side, it brings me to the right side.
Here is my code:
const float spriteWidth = 5.0f;
const float spriteHeight = 14.0f;
float x = position.X;
float y = position.Y;
if (bounds.Intersects(tileBounds))
{
if ((x + spriteWidth) > tileBounds.Left)
position.X = tileBounds.Left - 5;
if (x < tileBounds.Right)
position.X = tileBounds.Right;
if ((y + spriteHeight) < tileBounds.Bottom)
position.Y = tileBounds.Bottom;
if (y > tileBounds.Top)
position.Y = tileBounds.Top - 14;
}
I just don't see why it would do that. I am calling this function from the Game1.cs Update function, FYI.
And it only works for one tile out of a possible many, but that's for a later question...
Does anyone have an idea why it would do this? Thank you very much.