Of course, nothing changed except the speed. Rewatch the second video. I am having lower FPS there (100+ players nearby) and animations are damn smooth. I cannot achieve that.
On the first, weak machine around 20 frames. On another around 70. Both have the same issue. And I can notice why. PartialTicks are unequal, so that xOffset is unstable, which causes jumping animation.
Captured two videos for you. First one is mine, second one shows desired version. P.S. Look only on the top left corner, it contains "notification".
https://www.dropbox.com/s/kuh50e4tvnqn1kg/my notif.mp4?dl=0
https://www.dropbox.com/s/xle16vgqqjvz4kn/desired one.mp4?dl=0
Ok. Imagine drawing a rectangle with built-in drawRect function from Gui class. I am trying to move it SMOOTHLY across the screen. To be more simple: have you ever seen Windows 10 Notifications, that appear from the right bottom side of the screen? Thats what I am trying to recreate. Now it is moving "unstable", not smooth. Maybe I need to change incrementation of current value to much smaller value, but if I will do that - the speed of animation will be VEEERY slow. Reminding Windows 10 notification. Fast and smooth.
Offset? That is a number which represents how far will the rectangle move on the next frame.
Did everything you wrote: I am updating current every tick and rendering every frame. I logged the offset to the console and noticed that offset is not equal. I mean this:
Here is an updated code:
Every RenderGameOverlayEvent.Post:
float actualValue = this.lastTick + (this.current - this.lastTick) * partialTicks;
this.currentNotification.draw(actualValue);
ClientTickEvent:
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event)
{
if (event.phase != TickEvent.Phase.END) return;
NotificationsMod.NMANAGER.updateCurrent();
}
updateCurrent method:
public void updateCurrent()
{
if (this.currentNotification == null) return;
this.lastTick = this.current;
this.current += 2F; // Bigger number - faster animation
}
Even if I do
this.current++;
animation/offset are not "pretty".
Is that normal? Or am I stupid?
OK, I am a bit closer. You said
How can I get every tick? As far as I know RenderGameOverlayEvent is called every FRAME, right? So how can I manage to get every TICK?
Am I on the right way?:
private float current = 1, lastTick = 1; // "1" is wrong, cause it will lead to 0. It is obvious.
/*....*/
this.lastTick = this.current;
this.current = this.lerp(partialTicks);
this.currentNotification.draw(this.current);
/*....*/
private float lerp(float partialTicks)
{
return this.lastTick + (this.current - this.lastTick) * partialTicks;
}
@diesieben07, I got the logic, but imagine that current and lastTick get 0, so that accordingly to the formula actual = 0 + (0 - 0) * 0.xxxxx always equals zero. So current value will be 0. Next time it will repeat, again and again.