I've never Figured this out

Posted by LAR Games on Sept. 8, 2011, 3:58 a.m.

How would I go about making my game have a dynamic frame rate? What I mean by that is that when the fps go from about 60 to 40 or something, the speed and timing of the objects stays the same?

This has bugged me for the longest time, and I have experimented with it, but I can never get it to work.

How would you guys do it? Is it even possible in Game Maker?

Comments

LAR Games 13 years, 2 months ago

Wow. This got way more replies than I expected.. Anyway, blackhole seems to know a lot about this, so I guess I'm gonna have to experiment with with that to understand it fully. And no, I don't plan on staying with Game Maker forever. I'm thinking C++ or Java. Probably Java because it looks similar to GML.

EDIT: Meant C# not C++

colseed 13 years, 2 months ago

Both Java and C++ are similar to GML lol.

LAR Games 13 years, 2 months ago

Whoops I meant C# the advantage that has is being able to make indie games for Xbox. And that sounds really appealing.

KaBob799 13 years, 2 months ago

It would be easier to just have an adjustable fps instead of dynamic speed altering. So if you noticed you were lagging youd just go into the games settings and switch to a lower fps. Similar to delta time, but you don't have to worry about calculating the fps and can deal with nice fps numbers like 30 instead of 31.3244647. Not ideal for games that are only laggy at certain times, but perfect for a game that constantly lags some computers at 60fps but runs fine at 30fps.

Castypher 13 years, 2 months ago

Only thing I've got so far is a way to automatically reduce particle effects if the framerate drops.

Alert Games 13 years, 2 months ago

particle effects are hard to keep efficient to keep the framerate. But this is usually the case with older computers.

I like kabob's answer. as for me, I dont intend to be a game designer so I really dont care to be this technical. :D

JID 13 years, 2 months ago

Quote:
If you are doing it right, it shouldn't increase the complexity, simply add a multiplication to several values. Compared to the kind of complexity you can get in an RTS, doing delta compensation is trivial. Whether or not its worth it in GM is debatable, but if LAR intends to move to anything else ever then it would be good practice for him.
This.

Also, if you need help with delta timing, I could help. I use delta timing for my game, and there's rarely any problems.

It's really simple, all I needed to make was one script and I had to make everything else compatible with it.

LAR Games 13 years, 2 months ago

Awesome. I'd love to know how you do it.

JID 13 years, 2 months ago

well, just setup a script called, "delta_time" then put this code in:

var _msDifference;
_msDifference = current_time-global.__timePrevious;
global.__timePrevious = current_time;

if (fps == room_speed) {
  return 1;
}

return _msDifference/1000*room_speed;

Next, just setup your variables in the create event of an object at the start of the game or whatever:

global.__timePrevious = current_time

global.deltaTime = 0

global.deltaFriction = 0

then in the step event, put:

global.deltaTime = delta_time()

Lastly, if you want to make an object move, for example do:

x += 5*global.deltaTime

Or, if you want to do an alarm event:

alarm[0] = 30/global.deltaTime

I suggest adding decimals to the time of the alarm event

(ex: alarm[0] = 30.123/global.deltaTime), because very rarely there are errors when the fps reaches a certain point sometimes. But you could simply avoid this if you take out error messages.

LAR Games 13 years, 2 months ago

Wow. This is amazing. If I ever finish a game with this in it, you're definitely getting credit for this.