Detinator10
Detinator10

Reputation: 123

Why is my screenscale null?

I am creating a scaling matrix for my 2d tower defense game with this code:

float screenscalex;
float screenscaley;
Matrix SpriteScale;
screenscalex = (float)_graphics.GraphicsDevice.Viewport.Width / 1366f;
screenscaley = (float)_graphics.GraphicsDevice.Viewport.Height / 768f;
SpriteScale = Matrix.CreateScale(screenscalex, screenscaley, 1);

However it says that where screenscalex is initialized that it is a null reference. Does anyone know what I'm doing wrong? I tried using GraphicsAdapter to get the width of the screen but it didn't work. Also, I haven't set the viewport to anything. Finally, moving the code to Initialize() just makes the game crash

Upvotes: 0

Views: 54

Answers (1)

willthiswork89
willthiswork89

Reputation: 617

You have to do this below base.Initialize() which is where that is initialized at..

Upvotes: 1

Related Questions