Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Limit frame rate in slick?  (Read 10922 times)
0 Members and 1 Guest are viewing this topic.
Offline Zerolife

Senior Newbie

« Posted 2010-06-02 01:31:32 »

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.
Offline kavoc

Innocent Bystander

« Reply #1 - Posted 2010-06-02 05:49:54 »

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


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.
Offline Zerolife

Senior Newbie

« Reply #2 - Posted 2010-06-02 15:25:46 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kappa
« League of Dukes »

JGO Kernel

Medals: 120
Projects: 15


« Reply #3 - Posted 2010-06-02 15:53:24 »

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


float speed = 0.1f;

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

Offline Zerolife

Senior Newbie

« Reply #4 - Posted 2010-06-02 16:40:56 »

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.
Offline Nate

« JGO Bitwise Duke »

Medals: 167
Projects: 4
Exp: 14 years

Esoteric Software

« Reply #5 - Posted 2010-06-02 22:20:19 »

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.

Offline JL235

JGO Coder

Medals: 10

« Reply #6 - Posted 2010-06-03 00:09:16 »

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.

Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (25 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (202 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (771 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!