Best means of coding a "game speed" multiplier?

You see these sort of things in games like Crusader Kings and Rimworld. Sometimes players want the moment-to-moment of gameplay to speed by, so they click up the game speed. 2x, 3x, 4x ... That kind of thing.
But what would be an effective way of coding this? My immediate thought was just upping the room speed, but I feel this probably has some TERRIBLE side effects I haven't thought of.
Outside of that, maybe a universal variable that affects the animation speeds of everything in the game but... is that really the right choice?

Voice some opinions, I'm just spitballing ideas here, would love to hear input.
 

TsukaYuriko

☄️
Forum Staff
Moderator
This would generally be where delta timing comes into play. Once your entire game is based on delta time, you can simply plug one of those "universal variables that affect the speeds of everything" into the final formula, and just like that, you have a nice game speed slider without the "TERRIBLE side effects" of increasing the room speed (which, as you correctly guessed, exist - namely multiplying the performance your game drains!).
 

baconlovar

Member
My technique of choice is simply a global.timeMultiplier

it’s simple and resource efficient, only downside is that you have to remember to add it in the right places and can cause bugs if you multiply too high and don’t account for it (bullets skipping over things etc)

example

oPlayer.x += spd * timeMultiplier

timer -= 1 * timeMultiplier

or anything else you need to be manipulated by ingame time
 

Roldy

Member
Using an adjustable delta time is a decent solution, but you need to take care and think it through carefully. Consider animations, sequences and tile set animations. The play speeds of these will need to be adjusted as well. For visual effect and also if you have any logic or control that is based on animation frame/end, animation broadcast, sequence events, alarms etc...

It is doable, but you have to think it through.

However, if you make a decision to avoid using animation broadcast, animation end events, sequences, sequence events, alarms etc... then having a global time multiplier is definitely a simpler implementation.

Even if you adjust the actual room speed and use a fixed delta time you would need to adjust the play speeds of animations and sequences to achieve the desired effects.

If you plan on having some sort of time dilation or fast forward then your tasks will be easier if you make the decision to avoid using sequences or basing any logic on animation play speeds.

Alternatively, I would suggest that you consider thinking about your game and splitting your game model/logic from your game presentation. For your game model/logic you implement your own processing loop that you can call as many times as you want regardless of room speed, and then keep your game presentation within GMS's standard event loop and objects.

Think of your game as a client/server. Even though it is one application and single player you can conceptualize and compartmentalize your game data/model/state processing from the game's presentation/UI/IO... This way you can handle processing the server (possibly in a controller object's begin step) at what ever speed or multiple times per frame, separate from the speed that the presentation is handled normally through GMS's event loop. Again this would require you to not have game logic dependent on GMS features like animation or sequences or alarms.

Hope that made sense. I've done this a few ways and all of them take some thought if your game has any complexity. It is a good exercise as it will force you to get very familiar with many GMS systems.

EDIT: Even though there are mechanisms for controlling/adjusting the processing speed/time of the physics system I havn't messed with it. I imagine there would be some nuance in trying to get it to work with varying time.
 
Last edited:
Top