Jump to content

[1.11.2] Gui drawScreen not with FPS


SuperHB

Recommended Posts

I'm currently working on a mod that adds arcade machines into minecraft. I currently have the gui to render based on ticks. This isn't the best as depending on the FPS the game could run too fast or too slow. I was wondering if it is possible to render parts in GuiScreen#drawScreen consistently at different FPS?

Link to comment
Share on other sites

4 minutes ago, SuperHB said:

I currently have the gui to render based on ticks

Could you please elaborate on that? You can't render anything as a tick happens as rending must happen each frame due to buffers being cleared. A tick is a semi-constant 1/20th of a second. A frame is any numerical value depending on a magnitude of factors. 

Edited by V0idWa1k3r
Link to comment
Share on other sites

Considering above, there is a way to render based on ticks, and it is used by Vanilla entities, chests, etc... Very often in the render/draw method, you get a float parameter partialTick. It is between 0 and 1 and it represents how much in-between 2 ticks the current frame is. Use it to interpolate between previous and next tick and you get smooth transitions / animations.

Link to comment
Share on other sites

The updateScreen method in GuiScreen is called once per tick and can be overridden in your custom GUI.

If you were to make a spinning wheel, for example, you would update the rotation of the wheel every tick in the updateScreen method and then make the wheel spin look smoother in the drawScreen method by using partialTicks.

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Link to comment
Share on other sites

18 hours ago, V0idWa1k3r said:

Could you please elaborate on that? You can't render anything as a tick happens as rending must happen each frame due to buffers being cleared. A tick is a semi-constant 1/20th of a second. A frame is any numerical value depending on a magnitude of factors. 

I have a tick counter variable and when that reaches a certain number, the code inside the if statement will run. The problem with this is that the speed of the animation now changes depending on FPS.

Lets say that every 20 ticks I have the code run. In game, if I get 20 FPS the animation will be slow, but if I have 200 FPS the animation will speed up. I'm wondering how I can stop it from doing this, to keep a consistent speed when the game is running at different FPS.

Link to comment
Share on other sites

24 minutes ago, V0idWa1k3r said:

As @Earthcomputer said GuiScreen::updateScreen gets called each tick so operate on your timer there. You still have to render each frame obviously.

This is my first time working with partialTicks. I'm guessing I have to use this formula?

partialTick + partialTick * (currentTick - previousTick)

I have the previousTick and currentTick updated in updateScreen like so:

@Override
public void updateScreen () {
    previousTick = currentTick;
    currentTick++;
}

But I'm not really sure what to do in drawScreen to make sure it runs the animation consistently

Link to comment
Share on other sites

partialTicks is the amount of a single tick that had passed. Using it depends on the way your animation is done. For example if you have a wheel a rotation of which equals to the amount of ticks the GUI is open you would get it's rotation angledeg like this:

ticksExisted + partialTicks.

You don't need to store a previousTick in this case as previousTick always equals currentTick - 1.

Edited by V0idWa1k3r
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.