I’m at a loss with this one, tried a number of things, so here’s hoping someone’s got an answer for this one
Some background details:-
I’ve created a game which runs buttery smooth on Windows and currently I’m trying to get working well with Android however the performance is pretty bad and despite it being quite simple with small numbers of sprites the game stutters terribly. So, to try and get to the bottom of this I’ve created a fresh Android project with the default code from the Visual Studio template and added in just one sprite, but even this is stuttering, not to the same extent, but I was expecting just a one sprite game to have the sprite movement on Android super smooth or at least without stutter.
I’m using the default Android virtual device created when Visual Studio sets up all the Android tools or whatever when you create and run an Android monogame project. Obviously its not super powerful, but we’re talking 1 sprite here.
I’m guessing I’m missing something somewhere, but I’m out of ideas… unless the emulator is that slow that 1 sprite cannot move smoothly across the screen???
I’ve checked some other links/questions similar to this but don’t seem to help or be the same problem:-
Here’s the bare bones code I’m using below to try and get to the bottom of this. Note that as commented below, I’ve tried various combinations of various graphics or game timing settings, but none give stutter free performance - below is the combination I’ve found to be the best so far…
P.S. I’ve also deployed this to an Android device and the performance is pretty much the same as the emulator…
Anyone any ideas? Help…
public class AndroidTestGame : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private Texture2D _testSprite;
private Vector2 _position;
private Vector2 _velocity;
public AndroidTestGame()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
// Tried all sorts of combinations of these, and also with all of them commented out, some make it a bit
// smoother but still bits of stutter with any combination. Especially
// stuttery just for the first couple of seconds!
IsFixedTimeStep = true;
TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);
_graphics.IsFullScreen = true;
_graphics.SynchronizeWithVerticalRetrace = true;
_graphics.SupportedOrientations = DisplayOrientation.Portrait;
_graphics.ApplyChanges();
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
_position = new Vector2(50, 50);
_velocity = new Vector2(0, 4);
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
_testSprite = Content.Load<Texture2D>("TestSprite");
}
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
_position += _velocity;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
_spriteBatch.Begin(sortMode: SpriteSortMode.Deferred);
_spriteBatch.Draw(_testSprite, _position, Color.White);
_spriteBatch.End();
base.Draw(gameTime);
}
}