Hello,
I recently got a screen multiplier code to work, so now I’m looking into how to actually draw stuff on screen. But the first issue is that I don’t know how to conditionally draw stuff on screen. Like, all of the sprites in the game are not going to be on screen at once. How do I decide which ones are drawn and which one aren’t? Also, how do I decide what content is loaded at any given time? You probably don’t need to have your gameplay assets loaded when you are sitting in title screen or something like that…
In case it is needed, here is what I have now:
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private RenderTarget2D _nativeRenderTarget;
private byte _windowMultiplier;
private int _screenWidth;
private int _screenHeight;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
_windowMultiplier = 2;
_screenWidth = 640;
_screenHeight = 480;
Window.Position = new Point(
(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / 2) - (_screenWidth),
(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / 2) - (_screenHeight)
);
_nativeRenderTarget = new RenderTarget2D(GraphicsDevice, _screenWidth, _screenHeight);
_graphics.IsFullScreen = false;
_graphics.PreferredBackBufferWidth = _screenWidth * _windowMultiplier;
_graphics.PreferredBackBufferHeight = _screenHeight * _windowMultiplier;
_graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(_nativeRenderTarget);
GraphicsDevice.Clear(Color.CornflowerBlue);
// Apparently I'm supposed to draw stuff here, but how?
GraphicsDevice.SetRenderTarget(null);
_spriteBatch.Begin(samplerState: SamplerState.PointClamp);
_spriteBatch.Draw(
_nativeRenderTarget,
new Rectangle(
0,
0,
GraphicsDevice.DisplayMode.Width * _windowMultiplier,
GraphicsDevice.DisplayMode.Height * _windowMultiplier
),
Color.White);
_spriteBatch.End();
base.Draw(gameTime);
}
}