Results 1 to 2 of 2
  1. #1
    trader5050 is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default Comments on my FPS solution

    Hey there,

    I've come up with a rather simple FPS solution and I'd like some feedback. I have a separate thread for moving objects, fading them, etc. The main component simply redraws constantly, with all of this other stuff handled in my effects thread.

    This isn't the exact code, but you'll get the idea. (I'm posting from work and it's at home.)

    Java Code:
    long fpsTimer=System.getCurrentMillis(); //initialized early on
    int fpsCounter=0;
    int fpsDelay=(int) (1000 / CONSTANT.desiredFPS);
    if (System.getCurrentMillis()-fpsTime >= 1000) {
            if (fpsCounter>CONSTANT.desiredFPS*1.10) { fpsDelay++; }
            if (fpsCounter<CONSTANT.desiredFPS*0.9) { fpsDelay--; }
    The only problem I have is that even on my quad-core supershitz whatever PC, the framerate still fluctuates a decent amount, which I find odd. Right now I have only a single box being custom drawn and moved on the screen. My desired FPS is 60, but I'll see it drop to 54 or go up to 60-some. I find that odd considering how simple the program is and the fact I don't have any intensive tasks running. This results in animation that 'jumps' a bit on the fluctuations.

    I know it's not amazing, but it's relatively simple and seems to work, mostly. One thing I just thought about is that I need to tell the screen to only redraw 1/60 seconds, instead of constantly, as there's no need because the items themselves haven't updated yet...

    Any feedback would be great!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    On MS Windows machines the sleep method only has a resolution of 1/18 seconds or so; that would explain the fluctuating fps rate ...

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Are my comments correct?
    By twiggy62 in forum New To Java
    Replies: 2
    Last Post: 02-08-2010, 06:34 AM
  2. Any comments, can anyone simplify it further?
    By PeterFeng in forum New To Java
    Replies: 3
    Last Post: 01-15-2009, 06:45 PM
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-19-2007, 09:43 AM
  4. Eclipse - comments
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-07-2007, 03:56 PM
  5. Comments in java code
    By lenny in forum New To Java
    Replies: 3
    Last Post: 07-25-2007, 08:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts