문제

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