Hi everyone I've recently started to make my own platform game, I've managed to create the map using a 2d array and have also created my player with movement. I'm now stuck on how to approach the rectangle collision side any help is greatly appreciated.
Here is how I have created my map and now I just need to figure out how to approach the collision.
List<Texture2D> tileTextures = new List<Texture2D>();
private const int tileWidth = 64;
private const int tileHeight = 64;
public void Draw(SpriteBatch spriteBatch, Camera camera)
{
int tileMapWidth = tileMap.GetLength(1);
int tileMapHeight = tileMap.GetLength(0);
for (int x = 0; x < tileMapWidth; x++)
{
for (int y = 0; y < tileMapHeight; y++)
{
int textureIndex = tileMap[y, x];
Texture2D texture = tileTextures[textureIndex];
spriteBatch.Draw(
texture,
new Rectangle(x * tileWidth - (int)camera.cameraPosition.X,
y * tileHeight - (int)camera.cameraPosition.Y,
tileWidth,
tileHeight),
Color.White);
}
}
}
update, method, and you can just iterate over all your players, and tiles, and make a new rectangle, and check for collisions there