Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  Constant Frame Rate  (Read 2452 times)
0 Members and 1 Guest are viewing this topic.
Offline lucazd

Senior Newbie





« Posted 2005-07-22 02:07:34 »

Hello again, I have another question.

Some small devices are faster than others, this will affect my game fps or it is handled (somehow) by J2ME?.
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #1 - Posted 2005-07-22 05:53:36 »

You have to take care of it yourself. Aim for 10/15 fps or something like that - 30/60 fps is typically unrealistic.

Offline lucazd

Senior Newbie





« Reply #2 - Posted 2005-07-22 18:45:44 »

...thanks again
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lucazd

Senior Newbie





« Reply #3 - Posted 2005-08-04 05:17:09 »

I don't know how  Undecided.

With J2ME I use System.nanoSeconds(), but J2ME doesn't have it.
Any example J2ME game loop  Huh

Thanks!
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #4 - Posted 2005-08-04 05:57:30 »

System.currentTimeMillis();

Offline lucazd

Senior Newbie





« Reply #5 - Posted 2005-08-05 05:01:17 »

I tried it, but I expect 16fps and I get up to 30fps  Undecided.

Well, I suspect its because this resturns milis, not nanos...  Sad
Offline hegan

Junior Newbie





« Reply #6 - Posted 2005-09-09 06:57:19 »

u can use System.currentTimeMillis() to get current time in million seconds.
then define your fps(10 for example, that is 100 million seconds per frame)
in your main loop of your game as follows

run ()
{
       while(loop)
       {
             _frameCoheranceTimer = System.currentTimeMillis();    // this is your timer

             gamelogic();    // your logic

             repaint();   // paint
             serviceRepaints();

             // limit your fps here
            while( (System.currentTimeMillis() - _frameCoheranceTimer) < 100)
                   Thread.yeild();
        }
}


     
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #7 - Posted 2005-09-09 09:11:27 »

That run loop will blow up on more phones than you can possibly imagine ^_^

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline caraiz

Senior Newbie




Java games rock!


« Reply #8 - Posted 2005-09-22 10:33:35 »

I use this game loop:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
inf FPS=20;
int fps_delay=1000/FPS.
long time=System.currentTimeMillis(),elapsed=0,fps_error=0;
while (thread!=null)
{
   elapsed=System.currentTimeMillis()-time;
   time=System.currentTimeMillis();
   // Update Game Logic.
  update((int)elapsed);
   // Repaint.
  repaint();
   serviceRepaints();
   // Sleep.
  try
   {
      long t=System.currentTimeMillis();
      elapsed=fps_delay-(t-time)-fps_error;
      if (elapsed>0)
      {
         thread.sleep(elapsed);
         fps_error=(System.currentTimeMillis()-t)-elapsed;
      }
      else
      {
         thread.yield();
         fps_error=0;
      }
   }
   catch (Exception ex)
   {
   }
}


I use fps_error to correct "time errors" generated by thread.sleep(), without it the framerate is a bit worse if the sleep has not so much accuracy.
Maybe thread.yield() could be replaced by thread.sleep(1) to be sure it permit others threads execute, possibly we will lost some fps, but it will work better.

I use it in my qames for a lot of phone models, i think it works well, but suggestions are appreciated!!  Wink

Best regards

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.

TehJavaDev (18 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (70 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!