Playing with Frames...Frames as images, fps control, etc

Started by arianaa30, November 17, 2013, 01:37:54 AM

Previous topic - Next topic

arianaa30

Hi there,
Is there any ways to control frames generated by the game?
I want to for instance access the frames as images, say consequent .jpeg images.
Another thing in mind is limiting the fps, say I want always have a 20fps. It was best to provide an API class for them  :P

EgonOlsen

You can get the pixels of a rendered frame from FrameBuffer.getPixels() and create jpegs out of that. However, this can be slow on hardware, so it's nothing that you want to use during a normal application run.

About the frame limiter: jPCT is a 3d engine, not a game engine. That's why it doesn't provide direct API support for game loops and similar stuff. It's up to you to create something that fits your application. You can find a simple example in the Alien Runner sources (where Ticker.getRawTime(); is simply "return System.nanoTime() / 1000000L;" )


long sleepTime = (GameConfig.sleepValue - ft) - sleepDiv;
if (sleepTime < 0) {
// Sanity check, but this shouldn't happen
sleepTime = 0;
}
if (GameConfig.throttling) {
long st = Ticker.getRawTime();
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
//
}
long et = Ticker.getRawTime();
sleepDiv = (et - st) - sleepTime;
} else {
Thread.yield();
}