Point of Contact Blog 3 – Latency and FPS

Game production can be slow and painful finding and fixing the errors that are throughout your games, however i’ve come across a game designers worst nightmare: A game which lags due to too much content. There are only a few viable ways of solving this problem and the lag difference varies on the graphics the computer has so finding a balance of aesthetics and speed is of the utmost importance. If your having some lag trouble in your game maker game, read on to pick up some great tips on reducing or eliminating the lag.

Now I can’t lie, my games been progressively getting slower each time I work on it, until now i’m getting 20 fps at the most graphically intensive parts and my pc is a beast (If you’d like the specs check out the WIFI page at the bottom) which means anything less than I have will lag even more.

Now the trouble with lag is finding the cause, this is quite difficult without individually removing each “slice” of the game and running it separately and recording the fps and increasing that until it lags. By increasing “it” I mean adding more and more of that element until it’s at a set fps that you’ll stop at, e.g 30. Each time an element hits 30 you remember how much you’ve had to add to cause this lag. So if you started with 100 trees and it’s 60 fps you would continue to 200 which could be 45 fps, and finally you’d hit something like 500 which would be 30fps, therefore the difference between them is 500 – 100 = 400. The higher the resulting number the more efficient the code is.

Another example is if you have 1 enemy at 60 fps, and you add 2 more and get 30fps, that’s a difference of 2 so it’s very inefficient and I would either re-program it or at the least have a look to see what’s causing it to be so slow.


 

Below are a few tips that would help you reducing lag in your game maker game:

1. The number one cause of lag is stupidity, prove me wrong?
There’s just so many small unnoticeable things that can pass you by without thinking that could cause an infinite loop or slow down the game greatly. Planning your game out to the letter is highly recommended and it also stops unnecessary errors occurring which when you find you’re like “How did I even do this?”.

2. Instance deactivate is your friend.
There’s usually over 1000 instances at a time in games and they are all executing code multiple times every second. This code is used to disable any instances you wish or any instances outside the view which aren’t visible to stop them executing code. This is the number one lag reducer, although using deactivate_region deactivates ALL the instances outside the view so I would recommend individually deactivating instances if your working on a puzzle game where some elements outside the view need to keep executing.

3. Disable synchronization to avoid tearing.
This really doesn’t do much for the game unless you actually are experiencing tearing in your game. If you don’t know what tearing is, it’s an offset in a picture that has been moved on the horizontal axis. So imagine a picture, then split the picture horizontally and move the bottom piece right or left 20 or so pixels and you have a tear. Very few games suffer from this but by default the button is off anyway. It’s located in: (Global Game Settings > Resolution)

4. Destroying instances and particles.
I must admit i’m not so good at this one, mostly the destroying the particles side however, which when left alone after the particles aren’t being created anymore they continue to use memory. The simple line: instance_destroy(); is such as great tool, just remember the rule: If your finished with it, destroy it!

5. Precise collision checking is slow.
Usually in-game you would need precise checking for collisions for realistic physics and interactions, in menu systems you don’t need pixel perfect collisions such as with the menu buttons and this is a simple and effective way of reducing some of that lag. You can turn it off in the sprite editor and make your life a lot easier.

6. Game priority.
This is a nifty little feature that assigns more or less processing time to your game and less to any background applications that may be running to increase the speed of your game. It’s found in: (Global Game Settings > Other) and the options you have for this are: Normal, High and Highest, Highest being the fastest.

7. Use constants instead of Variables where possible.
This is another feature I didn’t know about until very late in my game, setting constants through the menu: (Global Game Settings > Constants). If you have no idea what constants are, they are simply static variables that you are able to change while editing the game but remain the same throughout the game. So if I wanted to set how fast the player is in the game I would set “Player_Speed” with a value of “5” as a constant and that will always be the same. Although your not just limited to 5 as the players speed, your still able to do: speed = Player_Speed + Extra_Speed; with Extra_Speed being a speed bonus given to the player with a power-up or something.

8. Use tiles.
Instances are objects with code that execute multiple times per step and are much, much slower than tiles, which are just images of objects used for creating scenery such as floors, houses, terrain and much more.

9. Use the minimum amount of instances where possible.
Another simple one is to remove any instances the player has no chance of colliding with, such as outside corner blocks as this will reduce the amount of objects game maker has and thus eliminating some un-needed lag. You can also replace them with tiles as well if it’s still visible by the player.

10. Optimize code.
Instead of using lots of “if” statements to determine if a variable equals a number, use a switch statement instead as it’s executed faster and a lot simpler to type. There’s generally a rule that goes: The less code you have that achieves the same purpose the faster it’s executed. Although this is un-done by using some of game makers slower functions such as: surface_getpixel(), execute_file() and variable_local_set().


 

Now those are the top 10 ways of reducing the lag, in some cases however you simply won’t be able to do anything to reduce the lag, being a cumulative addition of many, many features which are already optimized, such as in my game. Therefore if this happens to you, which I sincerely hope it doesn’t, the best thing your able to do is to re-think the game and add less features or upgrade to a newer version of game maker which supports hardware acceleration which is the path i’m taking.

Tagged , , , , . Bookmark the permalink.

About fluidicice

Australia.

Leave a Reply

Your email address will not be published. Required fields are marked *