I created a simple project to test Monogame on Android.
It’s a simple square moving across the screen. Besides being not
FixedTimeStep the movement looked laggy. I added a fps log
and observed jumping frametimes.
I ran this code on a Nexus 6 and Nvidia Shield Tablet both on Android 6.0.1.
Is this a known issue and is there a way to resolve it?
I attached my code below.
The fps log shows the following with an empty screen (no touch):
[0:] 37,8277776937161
[0:] 61,445442591523
[0:] 44,8865268600977
[0:] 41,554642276862
[0:] 48,3799958393204
[0:] 34,3719387492052
[0:] 45,1326674760458
[0:] 37,8303535624844
[0:] 44,59070194683
[0:] 46,2705904127337
[0:] 41,9431418768717
[0:] 51,318368896963
[0:] 56,7057369194041
[0:] 61,6340417139194
[0:] 43,6637368299254
I noticed when touching the screen the fps
comes more stable until releasing the finger (with touch):
[0:] 56,0616678346181
[0:] 53,591429658569
[0:] 65,5093350802489
[0:] 64,6274550354482
[0:] 74,0258202060879
[0:] 40,1679018296479
[0:] 108,335319480857 <---- How is this even possible on a android device vsyncing at 60 fps
[0:] 57,3841986870495
[0:] 56,1545372866128
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;
namespace MonoGameLagTest
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
public Game1()
{
IsFixedTimeStep = false;
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = true;
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 480;
graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>(@"TestFont");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
Debug.WriteLine((1.0d / gameTime.ElapsedGameTime.TotalSeconds).ToString());
spriteBatch.DrawString(font, (1.0d / gameTime.ElapsedGameTime.TotalSeconds) + "fps", Vector2.Zero, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}