Post by illdiewithoutpi on Oct 2, 2016 13:57:39 GMT -6
As some of you may know, the game Hyper Light Drifter (made in game maker studio) was recently updated to run at 60 fps, something which fans have been asking for due to its fast paced action. This was a huge undertaking for the development team, as they had to go in and manually change all of the constants they had set with 30 fps in mind to new values. This is a big problem with game maker in general which traps people with suboptimal settings, especially since the default speed of a new room is 30 and most new devs don't give it a second thought until it's too late.
Having your code based on the amount of time that has passed rather than frames is a much more flexible and reliable system that prevents things like this from happening.
Anyway, here's the simple piece code for framerate independence:
argument0 is the default value, and argument1 is the ideal fps. Suppose you want your player to move the equivalent of 4 pixels every frame at 30 fps, you write "scr_frame_ind(4,30)" and it will calculate a new value that will create the same result at any framerate, whether you're running at 30, 60, 120, 5, etc.
This simple little script isn't just good for changing your game to run at a higher speed, but it also prevents people with crappy computers from having their game play slow down when frames are down. Plus, this code isn't just useful for movement. You can apply it to timers or anything else that would normally be reliant on your framerate.
I have a file attached below that demonstrates what it does.
Download!
The number in the top left displays the current room speed, which depends on the y position of the player (The top of the room is 1 fps, the bottom is 60).
No matter how fast the game is running, the player will still move at the same speed in real time.
Now go forth, and make framerate independent 60 fps games!
EDIT: If anybody is new and doesn't know where you can change the room speed (default fps) of your game, you have to change it in the settings tab of each room.
Having your code based on the amount of time that has passed rather than frames is a much more flexible and reliable system that prevents things like this from happening.
Anyway, here's the simple piece code for framerate independence:
///scr_frame_ind(val, idealfps);
//deltime is the amount of time that has passed since the last frame
var deltime = delta_time*argument1/1000000;
return argument0*deltime;
argument0 is the default value, and argument1 is the ideal fps. Suppose you want your player to move the equivalent of 4 pixels every frame at 30 fps, you write "scr_frame_ind(4,30)" and it will calculate a new value that will create the same result at any framerate, whether you're running at 30, 60, 120, 5, etc.
This simple little script isn't just good for changing your game to run at a higher speed, but it also prevents people with crappy computers from having their game play slow down when frames are down. Plus, this code isn't just useful for movement. You can apply it to timers or anything else that would normally be reliant on your framerate.
I have a file attached below that demonstrates what it does.
Download!
The number in the top left displays the current room speed, which depends on the y position of the player (The top of the room is 1 fps, the bottom is 60).
No matter how fast the game is running, the player will still move at the same speed in real time.
Now go forth, and make framerate independent 60 fps games!
EDIT: If anybody is new and doesn't know where you can change the room speed (default fps) of your game, you have to change it in the settings tab of each room.