Jump to content

Recommended Posts

Posted

Hello,

I currently have an item that it supposed to display something on screen when held. I do this by subscribing to the RenderGameOverlayEvent event. But, after some experimenting, I have found that this event runs more times per second with higher FPS than low FPS, which makes sense. The problem is that I want it to render at a certain speed without FPS changing the speed. How would I do this? Any help is appreciated!

Posted

Hi

 

I'm guessing you have an animation that you want to run at a constant speed, independent of the FPS?

 

In order to do that, you need to synchronise your animation to something that doesn't depend on the FPS.

Two ways I have used that work fine:

1) System.nanoTime()

2) MyGlobalTickCounter.getCurrentTick()  where I have an event handler for World Ticks which updates the global tick counter.

The major difference is whether the animation stops when the game is paused.

 

Your animation code then uses this timer to calculate position, or frame, or whatever.  For example, with a spinning wheel you might do

 

final long DEGREES_PER_SECOND = 50;
final long NANO_SECONDS_PER_SECOND = 1000 * 1000 * 1000L;

long now = System.nanoTime();
long rotationAngle = (DEGREES_PER_SECOND * (now - rotationStartTime)) / NANO_SECONDS_PER_SECOND;

drawMyWheel(rotationAngle);

 

or alternatively

final long FRAMES_PER_SECOND = 24;
...
long frameNumber = (FRAMES_PER_SECOND * (now - rotationStartTime)) / NANO_SECONDS_PER_SECOND;

etc

 

-TGG

 

 

 

 

 

 

 

 

 

Posted

I was actually messing with nano time and all that last night. I actually got pretty close, but your code looks a lot better. :P Thanks once again mate!

Posted

I'll give you one more option.  It is a bit excessive unless you have a reason to do this.

 

For one of my entities, I had my render option for tail movement in my entitiy and I setup a datawatcher between client/server.  Then I just looked at it for position during render.

Long time Bukkit & Forge Programmer

Happy to try and help

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.

Announcements



×
×
  • Create New...

Important Information

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