Lightweight delta timing solution for GameMaker: Studio and GameMaker: Studio 2
To use Delta, download the latest release for your GameMaker version, and add the scripts to your project. The easiest way to do this is to drag the scripts into the editor, or import them using the resource system.
If you would like to also use the
DeltaObject object, right click on
Objects in your resource tree, and select
Add Existing, then import the
DeltaObject.yy (GMS2) or
DeltaObject.object.gmx (GMS1) file.
Delta timing is a method of manipulating game components based on real time rather than steps. In GameMaker, when a user is unable to run your game at the desired step speed, it will run visibly laggy. Delta timing helps to fix this, by scaling movement, alarms and everything else based on how long it actually has been since the last frame.
This resource provides tools to make delta timing nearly trivial in GameMaker.
Delta exposes a small number of scripts to help with timing:
Initializes the delta timing. Call this as early as possible in your game, before anything requires delta timing. You can also find configuration values in the definition of this script.
Call this script on the
begin step event of a game controller - likely a persistent object that is in every room of the game. This updates the delta timing for use in other scripts.
The bread and butter of Delta. Returns the given number modified for the delta timing.
This works by multiplying the provided number by the current "step factor", a number representing how many "frames" have passed in actuality. For example, if your game is running at half the speed it should be, the factor would be
2, since things need to move twice as fast to appear normal.
// Keep speed smooth between frame slowdown speed = d(movespeed); // Keep the animation running smoothly image_speed = d(1); // Tick down a timer in real-time instead of frame count someTimer -= d(1);
A utility function to return the given number in frames that would constitute that many seconds. Useful for setting timers in real seconds. This function uses your current game speed to determine the result.
Delta exposes an object parent which automates delta timing for most usages: movement, gravity, friction and alarms, even integrating natively with alarm events!
DeltaObject to your game, then for any object which requires delta timing, set
DeltaObject as the parent.
DeltaObject, you will need to use
event_inheried() on the following events (if the child object has its own version of these):
- End Step
Once you have set your object to inherit from
DeltaObject, you can use the following instance variables in place of their counterparts to get delta timing for free!
These values will be converted into the correct values for delta timing, and managed internally to the object, then set as their GameMaker equivalents. When using these variables, do not use the GameMaker equivalents as well.
Note: DeltaObject is considered beta. While it closely approximates the math that GameMaker uses, it is not an exact 1:1 when slowdowns/speedups occur.
Delta is a part of the GM Core project.
Copyright (c) 2017 Michael Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.