I’ve got a question. I’ve been making simple games with MonoGame and now I was wondering, how do I locate the places on my map where the collisions have to be? Or is there another place to assign the collisions and import the map afterward?
Those are multiple questions up here, but my main question is what the title says.
Build a collision layer that consists of Rectangle objects in code. You can then check for for collisions like such:
If (playerRectangle.Intersects(CollisionRectangle)) {
//do something
}
That’s a simple example. Really your collision layer should contain a list of all the collision rectangles for the map. You can then call a method that accepts the player rectangle and returns a list of rectangles that the player rectangle collides with.
Beyond that, you could actually create an object that contains the collision rectangle as well as other properties (perhaps type? wall, ground, ceiling, etc…). This will make it easy to determine what should happen for each collision type. Your collision layer would contain a list of these objects.
It doesn’t matter if you are using tiles or one large image. Either way, the collision rectangles should have the same world coordinates as the pixels/sections of your image(s) for the map floors, walls, celings, etc…