How i can use the Camera2D in MonoGame.Extended ?


How i can use the Camera2D in MonoGame.Extended ?

I have this code ->

I have this line in my Draw method

spriteBatch.Begin(transformMatrix: camera.GetViewMatrix());

I am not sure what it does exactly, it might help you figuring out how to use it.

If anyone can give a greater explanation that would help us both I think.

1 Like

Yeah, so the purpose of the camera is to create a transform matrix that changes the way at sprite batch is rendered. That line of code you posted @lozzajp is exactly right and appears to be the only thing missing from the gist.

As you can see in the SpriteBatch.Begin documentation a transform matrix is used to:

Transformation matrix for scale, rotate, translate options.

In other words, we use the camera to transform the way a batch of sprites is rendered to the screen without actually modifying their positions, rotations or scales directly. This creates the effect of having a camera looking at your scene that can move, rotate and zoom in and out.

Btw… thanks for asking this question. I’m aware the documentation is lacking. These types of questions are a great motivator to improve the wiki. We do have example code in the demos that might help too.

1 Like

thanks :smiley: