Stencyl – Speed Up/Down, Fast Forward/Slow Motion

Being able to speed up, or slow down a game is useful in many instances. Think about Turret Defence games where you can speed up the game for durations that would otherwise be either boring, or taxing, to the player. (E.g. not enough is happening, or too much is going on.) It can also be useful in other situations, and can also be useful for achieving certain effects.

It’s quite simple to adjust the speed of a game in Stencyl, though you’ll need to use the ‘code’ block. I’m going to start off with the example.

[swf src=”http://www.jeffreydriver.co.uk/wp-content/uploads/2017/01/Speed-Test.swf” width=640 height=480]

In the above example, press SPACE to cycle through the available speeds. In my example it goes from 2 to 20 (in increments of 2.) It’s important to note that 10 is the default and stands for 100fps. A lower amount will speed up the game, while a number higher than 10 will slow it down.

NOTE: You cannot have a speed value less than 1 as it will cause the game to freeze.

Onto the Code

The code for this is really simple. In the image above you’ll see a number variable that sets the value. (In this instance it’s 10, the default value.) Obviously you can change this value in-game as you need. The code is below:

Engine.STEP_SIZE = Std.int(_Speed);

The ‘_Speed’ text in the ellipses is the internal name of the number attribute, so you’d change this to whatever the INTERNAL name of your attribute is. The internal name differs from the name that you gave it. It can be found by clicking the ‘attributes’ panel.