Author Topic: Playing with Frames...Frames as images, fps control, etc  (Read 1712 times)

Offline arianaa30

  • byte
  • *
  • Posts: 44
    • View Profile
Playing with Frames...Frames as images, fps control, etc
« on: November 17, 2013, 01:37:54 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Playing with Frames...Frames as images, fps control, etc
« Reply #1 on: November 17, 2013, 10:39:27 am »
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;" )

Code: [Select]
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();
}