質問

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

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top