Trigger time

Hi Arduboy Developers,

Let’s say you have an object that moves in 1-pixel increments across the screen. It’s animated and looks smooth 1-pixel at a time. But you want to vary its speed. You can’t change the increment, it has to stay at 1-pixel. So this makes me think of everyXFrames, but is there a better way?

Thanks.

1 Like

You can also keep track of it’s location in a grid that is higher resolution than the display, then interpolate from that to the display resolution.

Using everyXFrames() will work if slowing the speed by a multiple of the frame rate is acceptable.

In what sense, and why?

If you do that then technically you’d be effectively ‘changing the increment’.

Moving 1 pixel every 2 frames at 60fps is equivalent to moving 0.5 pixels every frame at 60fps,
hence moving 1 pixel every X frames at 60fps is equivalent to moving 1/X pixels every frame at 60fps.

Atlernatively you can actually move 0.5 pixels per frame by using floating points (float) or fixed points (from the Fixed Points library).


Interpolating would be excessively expensive - a simple round or truncate would suffice.

This is effectively what using fixed points or floating points would do anyway - with the fractional part representing the higher resolution grid, because they in fact represent fractions of a pixel.

I personally think you might be trapping yourself with only allowing the object to move 1 pixel. I think I know where you are coming from where you made an animation that works great if and only if it changes by 1 pixel. Now you want it to move faster, but all the work you put it in hinders on it animating by 1 pixel. Might be completely off the mark so let me know.

Would you mind sharing your code?

So are you saying:
The animation speed should remain constant regardless of the speed at which the object is moving across the screen, and the movement speed can change.

or:
The animation speed should change in proportion to the changing movement speed.

1 Like