Posted July 1, 201411 yr 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!
July 1, 201411 yr 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
July 1, 201411 yr 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. Thanks once again mate!
July 1, 201411 yr 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
July 1, 201411 yr Author Thanks for the replies! I ended up using TGG's first piece of code. Thanks delpi too.
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.