Monogame Extended: Help understanding the basics in how map/sprite rendering works with the Camera

Greetings dear Monogame Community :slight_smile:

I’m doing my best try to understand the basics in how the Matrices works in the general rendering system (that is, being drawing a sprite or a tiled map), with Monogame Extended.

So far I’ve found here some of the general bases, with no real game implementations, with examples. Looking at the forums and the web, I can find questions for people that already understand these basics and they go for more advanced (or custom) implementations.

I’ll try to be as clear (and punctual), as possible, of what I understand, so anyone willing to help will give me a hint in where to search or, better yet, enlighten the spot I just can understand:

  • In Game1 I’ve defined a camera with a viewport, which I make reference any time needed (that is, one implementation for the entire project). My idea here is: I only need one camera as it is only one screen shown at any given time… isn’t it? or should I create an instance of the camera each time it is called?

private BoxingViewportAdapter _viewport;
public OrthographicCamera _camera;

// …

protected override void Initialize() {
_viewport = new BoxingViewportAdapter(this.Window, this.GraphicsDevice, Window.ClientBounds.Width/3, Window.ClientBounds.Height/3); //Zoom*3
_camera = new OrthographicCamera(_viewport);

  • For rendering a map I have a class called “Mapper”, which draws based in a Monogame Extended TiledMapRenderer instance, as follows:

public void Draw(string layer) {
_tiledMapRenderer.Draw(_tiledMap.GetLayer(layer), Game1._camera.GetViewMatrix());

What I understand here is that the renderer draws the entire tiled map layer, and then puts the camera to LookAt the camera.GetViewMatrix… is that what is happening? I’m sure something “weird” is happening (rather, that I cannot understand), as when I draw my first map, everything works as expected (coordinates and such work as intended, as the collision system works without issues); yet, when I draw a new map (with a new instance of the Mapper class), this same drawing method now draws the tiledMap layer but with a sort of offset, as the collision system now is all messed up. My guess that it has to do with this second parameter, the camera.GetViewMatrix, but I cannot really understand how to make it work (is it there a “default origin” that is implicit in the first map I draw, which now is different when I draw my second map?).

Is there any place where I can read more deeply (or better yet, with more examples with implementations), so I can get better the way the rendering is working, so I can make the map and the camera to be positioned correctly as well?

Any hints or idea will be deeply appreciated… if someone is willing to explain the how-these-works it will be great :slight_smile:

Best wishes… please give any hint about these, as I cannot continue my game develop with no clear understanding of these :confused: