Changing sprites at a very specific frequency no matter the processor speed?

I need to be able to change between sprites at a specific frequency despite the differences in processor speed that each user’s phone may have. How do I do this?

I’d like to do it down to the 100th of a second.
If possible, I would also like to be able have users be able to choose what ever frequency they want on a timeline / graph and have transitions in speed in between each user selected speed in time. Then save it and play it back or play back other ones they have saved.

I realize this may be a very weird set of things to want to do, but hopefully someone can help me figure out how to do it. Thanks!

So keep in mind that at 60fps, the fastest you’re ever going to get (on any processor) is 1/60th of a second, because events can only occur every frame.

Outside of that, so long as it is longer than one frame, you could always use the TimeDelta() expression. It doesn’t care about framerate, and measures the time since the last frame. Play around with that and see if it gets you near what you’re looking for. (you’ll want to multiply TimeDelta by whatever number you’re wanting to calculate)

Thanks. I don’t need it to go faster than 1/60th, so I’m good there.
So can event’s not occur

So if I want to set sprites to change at exactly 9.95 times a second, is that possible? Or 5.18 times a second? In other wood it have to be in those examples would it only be able to display the change at 10 times per second, and 5 times per second to get it close, but not exact?

I have never been good with understanding math equations so I may be in way over my head even if it is possible.

Two things to keep in mind:

  1. Timers are framerate limited (not real time).
  2. Events can only occur during a frame.

With this in mind, if your framerate is 60 fps, you will never get exactly 9.95 seconds (1/60 = ~0.166667, which doesn’t divide evenly into 9.95 seconds). You will also not be able to get exactly 9.95 times a second for the same reason.

Even using timedelta I’m not sure you’re going to get to that specific frequency, because again, even though timedelta can track between frames, events can only occur during a frame.

OK. So it is probably only possible to have the change happen 1-60 times a second, but only on full numbers, not down to 1.1 or 1.11 level of detail?

You can get to micro-intervals, it’s just not going to be exact. It’ll be off by 0.016 ms if you have a 60fps game, 0.08 ms if you have a 120fps game, etc.

That sounds like it might be imperceptibly off. Which could be good enough.

I’ll start looking for tutorials that explain time delta and see if I can figure out how to implement it. If I can figure that out, then I can work on figuring out how to set up an interface and a way to save what users choose.


1 Like