We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › frameRate weirdness!
Page Index Toggle Pages: 1
frameRate weirdness! (Read 1302 times)
frameRate weirdness!
Apr 15th, 2009, 6:07am
 
hi! im new to processing, and have run across a bit of a problem. im using processing to make a little game, but the framerate is acting reallly weirdly, skipping all over the place, really jittery. ive tried using println(frameRate) to check whats going on, and its basically telling me that its running between 59fps and 60fps when ive set it to 60, and 29 - 30 when ive set it to 30. i tried switching the display mode to opengl, but then i just get vertical blank problems.
my code is set up like this-
Code:

varible declarations,

void setup(){
size(640, 480)
frameRate()
image loads and variable assignment,
}

void draw(){
update game logic
draw stuff
}

a few void functions(){
}


does anyone have any ideas about what im doing wrong? is my code in the wrong place?
thanks - una.x

Re: frameRate weirdness!
Reply #1 - Apr 15th, 2009, 8:28am
 
A possible reason for such glitches is that you generate lot of objects: when the garbage collector kicks in to collect objects you no longer use, it might take some time to do its job.
That's a general problem in real time Java programs, we see this even in JavaFX demos... I don't know if Java has an incremental GC which could be used instead.
Re: frameRate weirdness!
Reply #2 - Apr 15th, 2009, 8:36am
 
thanks for the reply, however i only have 3 objects on the stage at this point. any ideas?x
Re: frameRate weirdness!
Reply #3 - Apr 15th, 2009, 8:53am
 
It depends on what you do... Processing (and Java) can create objects behind the scene, eg. when you do loadPixels, call triangle(), etc.
Most of them are short lived, though.
What system do you use?
Re: frameRate weirdness!
Reply #4 - Apr 15th, 2009, 8:59am
 
hi. im on a macbook running leopard.
Re: frameRate weirdness!
Reply #5 - Apr 28th, 2009, 6:19am
 
Sad any help here?
Re: frameRate weirdness!
Reply #6 - Apr 28th, 2009, 10:44am
 
frameRate(60) means only call draw() up to 60 frames per second. If it takes a long time to actually do the calculations and drawing for each frame (you should include things like keyPressed(), mouseMoved() and so on), then the resulting frame rate can be lower.

According to the docs, the frameRate variable reports an average of the last few frames (it doesn't specify how many that is).

Ultimately, the resulting framerate is not guaranteed. I'd like a framerate of 100fps for some complex 3D scene, but it ain't gonna happen, at least not on my 4-years-or-so-old hardware.

As a further note, if the issue is with apparent smoothness of your animation, consider using time-based animation instead of frame-based animation. Instead of moving, say, 2 pixels per frame, have your speed in pixels per millisecond. You can call millis() (and compare the return value with the value from the previous frame) to work out how much time has passed, and scale your motions relative to that. There are issues to resolve regarding "acceleration", but programs don't typically use "exact" formulae for motion as it is, so you just need to deal with some approximations.

-spxl
Page Index Toggle Pages: 1