Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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 5484 times)
0 Members and 1 Guest are viewing this topic.
Offline Zerolife

Senior Newbie





« Posted 2010-06-02 03: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 07:49:54 »

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

Senior Newbie





« Reply #2 - Posted 2010-06-02 17: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: 75
Projects: 15


★★★★★


« Reply #3 - Posted 2010-06-02 17: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

example

1  
2  
3  
4  
5  
6  
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 18: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 Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2010-06-03 00: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 02: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
java-gaming.org 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‑gaming.org
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!