Extension for Adding Delta Time to Blocks

I’ve made an extension which allows Delta Time to be in blocks! This is a useful extension because you can take the delta block and multiply something a value by it, and if your project has a low framerate, or if you just want it to work well on hardware/mobile devices, objects will move at normal speeds instead of slow motion.

Here’s the extension: https://github.com/kiwiphoenix364/pxt-deltatime
Paste this into the search bar of the extensions page on the editor and click the extension that comes up. Then your block should be added. Also, @UnsignedArduino, it’s your choice whether you want to or not, but you could add it to your “Awesome Arcade Extensions” Github page.

3 Likes

Could you give an example on how to use this? Little confused on what the delta block actually represents. Milliseconds since last frame?

2 Likes

If the gap between frames is larger than normal, it will output a higher value, equivelant to if the dropped frames were there. If you set a speed or acceleration (you have to set it every frame so it detects what the delta variable is every frame) to " * delta", then if frames are dropped, the delta time variable will account for that.

1 Like

I tried to make an example, but it doesn’t seem to work lol

Could you help me fix it? I’ll add it to the list once I get an example for this.

Sorry, I didn’t have the math right… I got it right now, and you can see very well here how it works:

You can change how laggy it is with the up and down arrows. The bottom one moves the same speed, no matter the framerate. You can also use the top one for reference, as it does not have delta applied to it. The multiplier level is below, the number of times the top one has gone across the screen is in the life counter, and the score counter shows how many times the bottom one has gone across the screen. Sorry I had the extension messed up before…

2 Likes

I’ve made a new demo (no updates to the extension, I’ve just made the demo more “usable”)

2 Likes

whats Deltatime (This guy is dum)

1 Like

I explained it briefly in the demo above, but what deltatime does is it tells the time in-between frames. This extension takes that time and makes it so that moving objects ignore frame drops, so for example if there are half the frames in a second, an object will go the same distance as if the game had full fps. (You can multiply a value by (like in a set velocity block you would do set “velocity = [velocity] * delta”) the new variable in the next for it to compensate for frame drops) This can be useful for slow projects or stuff on hardware that has a low fps.

1 Like

Wait… you can reduce lag???

1 Like

That’s not quite how DeltaTime works. The lag persists, there’s nothing you can do about that, however using deltatime can make it seem like the game is running a lot better than it really is.

Deltatime values are calculated through a formula that depends on the FPS. The lower the FPS, the higher the deltatime multiplier is. For example, when the FPS is 60, the multiplier will be 1. But as the performance gets worse, the number rises.

You can then implement this in your code by multiplying values that affect what’s on screen with these numbers. Eg. you multiply how fast a sprite is moving (as shown in the demo above).

If you want your game to feel like the sprite is moving 10px/s, you will forever set its speed to 10 * deltaTime.

This way, if the FPS is high, the sprite will move at 10px/s, but if the performance drops, the deltatime value will increase the speed to combat the lag. That way, it will seem like the sprite is moving at a normal rate. I hope this helps

2 Likes

It helps you compensate for lag, not reduce it.

3 Likes

bro really just summed it up better in one sentence than my whole paragraph :skull:
my career is over

2 Likes

Hehehe…

1 Like

Well, it turns out that this project was just kind of an estimation and I was using velocity so it didn’t matter (lol all I was “compensating” for was the time the sprite takes to move back to the front of the screen I think. I’m not sure if that is exactly the case but that’s what it looks like to me.) I’ve updated it… again… Basically, velocity has some sort of its own compensation system in it. Now, I’ve tested it out with just changing the position manually and it works. I also had to fix some things because it’s only the amout of time for the frame to stop rendering (not when it is shown), and it is locked at 30fps, so I had to make it so that deltatime is locked to 1 and not going below that. I also added a raw variable that is just the time it took to complete a frame. This vid that I watched recently made me want to go back and look at my implementation in Arcade (and how terrible it was), and also shows how exactly to use it in games. I then decided to fix the extension and yeah… If you’re using deltatime and the player is changing speeds, just keep in mind that to be precise you’ll need to do a bit more than multiplying your variables by deltatime.

Again, that’s kiwiphoenix364/pxt-deltatime.
Sorry for giving misinformation. Only use this to multiply deltatime if you’re changing the position manually. Just wanted to fix this, especially since it was messed up AND on @UnsignedArduino 's website.

3 Likes