Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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!

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

 

 

 

 

 

 

 

 

 

  • Author

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!

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

  • Author

Thanks for the replies! I ended up using TGG's first piece of code. Thanks delpi too. :P

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.