[Fixed] Massive frame rate issues on new project

Recently, I decided to make the switch from GM to Monogame and am beginning to code my first project. I added basic player movement and ran the game, only to be horrified by the lag-spikes that happen once every few frames. Basically, my player character moves around 5 pixels smoothly, then teleports another 15.
In the end, I simply decided to pull out razor cortex and ran the game boost, which reduced the lag spikes to once every few seconds and they are barely visible.

So my question is, should this be something I should be worried about in the future? Or is it simply my PC that gives this problem and the project should work fine on other devices. There is currently nothing but the player class, default stuff and a class for collision objects.

I’m using a 5 year old Windows 8.1 gaming device with latest Nvidia drivers(I don’t think because it’s for 3d). It’s still pretty strong, but it’s quite cluttered. Edit: Monogame is version 3.4 with Visual Studio 2015(The pipeline in 2017 doesn’t work for me)

Hey and welcome! :slight_smile:

Hmm, not sure what causes this. Could you share your code for moving the player? Do you use the gameTime passed to Game1.Update or do you have a speed per frame?

It might be the garbage collector. You can check when collections happen with the Memory Usage tool in Visual Studio. If you make a lot of allocations the garbage collector can cause lag spikes when it runs.

I also recommend upgrading to MonoGame 3.6 or develop. Lots of fixes have made it in since 3.4.

What’s not working? This should be easy to fix if you can clarify a bit.

1 Like

Hi, heres the code for player movement as requested.
bool right = KeyInput.IsKeyDown(Keys.D); bool left = KeyInput.IsKeyDown(Keys.A); float axis = ((right ? 1f : 0f) - (left ? 1f : 0f)) * spd; this.horizontal_move_input = (axis != 0f); if (horizontal_move_input) { if (axis > 0f) { if (this.velocity.X < maxspd) { this.velocity.X += axis; } } if (axis < 0f) { if (this.velocity.X > (maxspd * -1f)) { this.velocity.X += axis; } } }
this.position.X += this.velocity.Y;
I don’t use gameTime.ElapsedGameTime since it makes movement slower and doesn’t fix the lag when I tried it. Edit: these are ultimately called during Game1.Update.
As for upgrading to MonoGame 3.6, how do I do so? I think that might be the fix.

You can wrap your code in triple backticks ` to format it properly.

If you multiply your speed by gameTime.ElapsedGameTime.TotalSeconds, you should also multiply your base speed by 60, since it now is speed / s vs speed / frame (assuming you’re running at the default framerate of 60 fps).

You can grab the installer on the downloads page: http://www.monogame.net/downloads/

1 Like

So I installed MonoGame 3.6, and changed my reference to the 3.6 one, now it’s giving me the error(s):
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I put in using System.Runtime; that didn’t solve anything. My reference version for System is I tried adding the reference via the solution explorer, but System.Runtime was already installed. Help would be appreciated, sorry for late response btw.

EDIT: Fixed it. In MG 3.6 the frame rate issues are non-existent.