Limit frame rate in slick?

I noticed that when I run slick, though it runs at a fantastic frame rate, it EATS my cpu usage. Is there a way to limit the frame rate to say 100 to cut back on cpu usage? Right now its running at like 2000 fps, and thats a bit excessive.

app.setVSync(true); - tries to keep the frame rate the same as the monitor refresh rate

or

app.setTargetFrameRate(int); - lets you specify a desired frame rate.

Of course app is your AppGameContainer.

The Slick Wiki has more information about other ways you can control game updates as well. Also, a search on the Slick forums turns up a few interesting discussions about which methods people prefer. I personally just turn on vsync and use delta to control the logic updates.

if you could, give a brief overview of how delta keeps things where they should with the logic update? I’ve seen examples of it, but can’t seem to find a description of it on slick wiki. I think I’m going to need to use it, but I have no idea how to yet.

the delta value is the amount of time that has passed in milliseconds since the last time the update method was called. (it’ll return 0 if less then 1ms and accumulate until 1ms passes)

so to get constant movement independent of fps you simply multiply speed by delta

example



float speed = 0.1f;

public void update(GameContainer container, int delta) {
     x += speed * delta;
     y += speed * delta;
}

That makes perfect sense. Alright, I’ll have to use that then. No need to worry about the frame rate pushing to the max if everything stays with the correct speed then. Thanks a lot.

Max frame rate can make boss video cards audibly squeal as they render a simple 2D game at 3500 fps. At least limit it to something reasonable, like 120.

Also at very high frame rates delta time can get a bit dodgy. Especially when you get jumps from 60 fps to 3000 and back.