I am sorry if this was already answered but I couldn't find the answer. So I am doing a tile based platformer and when I was making collision I had quiet a struggle I looked here and googled for answers but they all seems to be overcomplicated for such a simple task/game.
I did come up with this code and it works almost fine:
Rectangle boundRect = new Rectangle((int)position.X, (int)position.Y,
(int)(sprite.Texture.Width * scale), (int)(sprite.Texture.Height * scale));
Vector2 previousPosition = position;
Vector2 previousVelocity = velocity;
if (boundRect.Intersects(collider))
{
velocity = Vector2.Zero;
position = previousPosition - previousVelocity;
}
It works almost as good as I want, axcept few things. When I constantly move (i.e.) to left of a collider object(tile) my player sprite is shaking, if thats right word to use, for like 1-3 pixels from edge of object, also in this state I can't move any other direction (i.e. jumping up) till I stop my current movement.
So my question is basicly: "Can I improve this while keeping simplicity, or I need to use better(more complex) approach?"
P.S. Sorry for my English, it is not my native language.