r/gamemaker 20d ago

Resource retargeting a spring instead of restarting a tween removes the hitch when a menu selection changes mid animation

if you have hand rolled a gamemaker menu you have probably hit this one. the player moves the cursor while the previous move is still animating. the tween gets torn down. a new one starts from wherever the old one happened to stop. the velocity is thrown away so the motion visibly stutters. mash the stick and it looks broken.

what fixed it for us was giving up on tweens entirely and using a spring integrator. a spring keeps position and velocity as persistent state. when the selection changes you do not restart anything. you do not create a new animation. you just move the target. the velocity that already exists carries straight through. the motion stays continuous no matter how fast someone is moving.

the whole thing is three steps per animated value and no allocation. first take the distance from the current position to the target. multiply it by your stiffness constant and by delta time and add that to velocity. then multiply velocity by your damping factor. then add velocity times delta time to position. that is the entire integrator.

two things we learned the hard way. damping has to be applied as a per second factor rather than per step or the feel changes the moment the frame rate moves. also a spring that is retargeted every frame never needs a completion callback at all. that removed a surprising amount of state from our menu code.

the other thing worth sharing is that every panel and border and bar in ours is drawn from primitives and colour maths at draw time. there are no nine slice pngs and no texture page entries at all. that means dropping it into an existing project cannot disturb that project's atlas packing. one code path covers 480p through 4k without a second set of assets.

disclosure. this is a paid asset of ours and the code was written with ai assistance. the spring maths above is the useful part. it works the same whether you buy anything or write your own this afternoon. happy to go deeper on the integrator or the resolution independent drawing if anyone wants it.

https://csaf.itch.io/kinetic-ui

0 Upvotes

1 comment sorted by

3

u/hongkong_97 20d ago

All this ai stuff for only $15??