Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (289)
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 1925 times)
0 Members and 1 Guest are viewing this topic.
Offline lucazd

Senior Newbie





« Posted 2005-07-22 04: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
« League of Dukes »

JGO Knight


Medals: 13
Projects: 2


I'm gonna wring your pants!


« Reply #1 - Posted 2005-07-22 07: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 20: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 07: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
« League of Dukes »

JGO Knight


Medals: 13
Projects: 2


I'm gonna wring your pants!


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

System.currentTimeMillis();

Offline lucazd

Senior Newbie





« Reply #5 - Posted 2005-08-05 07: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 08: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 Coder


Medals: 2


falling into the abyss of reality


« Reply #7 - Posted 2005-09-09 11: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!
Offline caraiz

Senior Newbie




Java games rock!


« Reply #8 - Posted 2005-09-22 12: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (60 views)
2013-05-17 21:29:12

alaslipknot (69 views)
2013-05-16 21:24:48

gouessej (99 views)
2013-05-16 00:53:38

gouessej (97 views)
2013-05-16 00:17:58

theagentd (107 views)
2013-05-15 15:01:13

theagentd (98 views)
2013-05-15 15:00:54

StreetDoggy (144 views)
2013-05-14 15:56:26

kutucuk (167 views)
2013-05-12 17:10:36

kutucuk (166 views)
2013-05-12 15:36:09

UnluckyDevil (175 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.124 seconds with 22 queries.