How can I use resolution scaling and a 2d camera at the same time?

Page 1 of 1

5 Replies - 1735 Views - Last Post: 20 April 2016 - 05:10 PM

#1 jmaslaki

Reputation: 1
• Posts: 9
• Joined: 02-February 16

How can I use resolution scaling and a 2d camera at the same time?

Posted 02 February 2016 - 05:40 AM

I got the resolution scaling down from this tutorial: The tutorial

And I made a class called Camera2D.cs from this tutorial: Other tutorial

But, in the main class(Game1.cs), in the parameters for spriteBatch.Begin() which is located in the Draw method, I can only implement either the resolution scaling or the 2d camera, and not both.

Is there a way I can implement both the 2d camera(allowing me to pan the camera and/or zoom in and out) AND have resolution scaling to fit a large resolution on a smaller screen? Thanks for your time.

Notes:

• I'm using Visual Studio 2015

Is This A Good Question/Topic? 1

Replies To: How can I use resolution scaling and a 2d camera at the same time?

#2 jmaslaki

Reputation: 1
• Posts: 9
• Joined: 02-February 16

Re: How can I use resolution scaling and a 2d camera at the same time?

Posted 02 February 2016 - 08:14 AM

I apologize for bumping, but I don't think I can edit the first post and I messed up. The second link of the tutorials should be this http://www.dylanwils...era-in-monogame

#3 basteagui

Reputation: 14
• Posts: 60
• Joined: 08-September 13

Re: How can I use resolution scaling and a 2d camera at the same time?

Posted 18 February 2016 - 12:53 AM

this is very simple, i am sorry i haven't checked the forum in weeks...

what you need to do is in your camera2d class, where you set up the matrices at the bottom, you multiply from the resolution independence tutorial this matrix:
Matrix.CreateScale(ScalingFactor); (in my case i multiply by scaler1 for width and scaler2 for height.

so your camera will be scaled by the zoom and the scalingfactor.

then, what you do is only pass the already correctly zoomed camera to your spritebatch

#4 jmaslaki

Reputation: 1
• Posts: 9
• Joined: 02-February 16

Re: How can I use resolution scaling and a 2d camera at the same time?

Posted 19 April 2016 - 07:54 PM

Can you please be a little more specific? I'm dumb

#5 basteagui

Reputation: 14
• Posts: 60
• Joined: 08-September 13

Re: How can I use resolution scaling and a 2d camera at the same time?

Posted 20 April 2016 - 03:47 PM

then go to the camera 2d tutorial, and follow THAT tutorial, if you have done it right you have a new .cs file on your project, a "class" that holds a little function or method that you can call up to run. hence 'camera2d class'.

the key for making your camera scale correctly lies in the following parts of the respective tutorials:
from resolution independence -
```//Calculate ScalingFactor
float widthScale = (float)GraphicsDevice.PresentationParameters.BackBufferWidth / virtualScreen.X;
float heightScale = (float)GraphicsDevice.PresentationParameters.BackBufferHeight / virtualScreen.Y;
ScalingFactor = new Vector3(widthScaling, heightScaling, 1);
Scale = Matrix.CreateScale(ScalingFactor);
```

and on the camera2d tutorial; -

```           Matrix.CreateTranslation(new Vector3(-Position, 0.0f)) *
Matrix.CreateTranslation(new Vector3(-Origin, 0.0f)) *
Matrix.CreateRotationZ(Rotation) *
Matrix.CreateScale(Zoom, Zoom, 1) *
Matrix.CreateTranslation(new Vector3(Origin, 0.0f));
```

again, the key is in these 2 bits of code i posted from each tutorial, scaling factor in resolution tutorial == zoom (CREATESCALE) in camera2d tutorial.

so if you implement both tutorials, first resolution independence, and then you add your camera2d class as per the second tutorial, you can make your camera act the way you want if you change the line that reads:
```matrix.createscale(zoom, zoom, 1)
```

into
```matrix.createscale(scalingfactor)
```

the variable scaling factor from the resolution tutorial

#6 basteagui

Reputation: 14
• Posts: 60
• Joined: 08-September 13

Re: How can I use resolution scaling and a 2d camera at the same time?

Posted 20 April 2016 - 05:10 PM

then in spritebatch only draw the camera and it will have the resolution independence zoom.
if you want the camera to be able to zoom more from there you can multiply createscale(scalingfactor) * createscale(zoom)