android stutter even on one sprite game

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 :slight_smile:

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
and here

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);
    }
}

I uploaded an AnimationComponent that move a sprite across the Screen.

In terms of performance it runs smoothly on my device. Both on KNI and MonoGame.

1 Like

Hi

Thanks for the reply…

I must be doing something wrong as I’ve downloaded and run your code (Visual Studio 2022) but all I get is a screen full of text (something about a fox) and an FPS counter?

It’s the same for the android and the Windows project, the FPS for android is saying about 30 if that’s any use? :slight_smile:

There are a couple benchmark components in the project.
It’s not very interactive at the moment. You’d have to manually turn then off and on.

Also, you’d have to turn on V-sync and FixedTimeStep.

Ah, I see what you mean, ok got it working now I’ve turned off the string component, enable the sprite/animation ones and turned on v-sync and FixedTimeStep too.

However, I’m still getting a bad visible stutter just like the test code I posted when using the emulator via Visual Studio. I’ve also deployed to my physical android device a Samsung A14 and I’m getting FPS fluctuating between 20 and 25 and then same stutter as with the emulator…

Dunno what’s going on, maybe its just not powerful enough of an android device to run this smoothly? I know the A14 isn’t super powerful, I just thought the performance would be better. This is the only physical android device I’ve got…

Thanks for the help so far, have you got anymore ideas?

Did you check if your A14 can run other games without issues?

Hi @magneticmuesli / @nkast

Thanks for the replies… Yeah, I found a simple tiny wings clone called ‘dragon fly’ and that’s super smooth, like 60hz from the looks of it, and no stuttering.

I’ve tried a few other games and whilst the A14 is pretty slow compared to all the iPhones I’ve got and used, it ran dragon fly fine. The performance of dragon fly is pretty much what I was expecting from my monogame game.

The only other thing I’ve found which improves performance and reduces the stuttering is not doing a Graphics.Clear() which seems to make quite a difference, although there still quite a bit of stutter on both the emulator and the A14 even with that.

I only got the A14 for simple testing on android as I’m an iPhone guy (sorry!) and didn’t have any android devices to test - apart from the default android emulator/vm/simulator thing that VS uses…

I suppose I should also be asking, is monogame android performance known to be a little slower than one might expect? Or do you think that this is something else?

At first I figured it must be something in my game code, but after testing my cut down game code (literally just one sprite) and the benchmaking code from @nkast it seems to be one of the following scenarios:-

a) monogame is a just a little slow on android and I need to accept it
b) or… my VS android and/or monogame setup is not working correctly and something is slowing it down

In my experience monogame has been running buttery smooth on android. Haven’t performance tested it to its limits by any means but just anecdotally I’ve had great framerates without stutters. So my guess is there’s something fishy going on in your setup.

Hi @magneticmuesli

I’m just wondering if this is anything to do with .NET 8 as I had to edit the project file and android manifest to make it build/run with Visual Studio after .NET 8 was released? Although saying that, @nkast had already made these changes to the benchmark code I used and I still get stuttering and slow performance with that too?

Hi @magneticmuesli / @nkast

I’ve done some more testing and tried the code from @nkast on another Windows machine (literally a fresh re-install of Windows 11 on another PC). Just installed VS2022 + monogame extension then re-ran the code and this seems to be ok. I get about 60fps with ‘Sprite’ component, about 20/30fps with the ‘Sprites’ component. Anyway, to cut a long story short I’ve re-installed Windows on my machine and this seems to have sorted it. Don’t know what was causing the issue…

Thanks for all the help