Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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  
  Good GameLoop for JavaFx AnimationTimer  (Read 298 times)
0 Members and 1 Guest are viewing this topic.
Offline pavul

Junior Devvie


Medals: 4
Exp: 4 years



« Posted 2018-09-12 17:18:11 »

hello, im using javaFX AnimationTimer for my game loop, i would like to know if there is another way to improve it, docs say that AnimTimer will run at 60 FPS or will try, below is my gameloop:



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
 gameThread = new AnimationTimer() 
        {

            @Override
            public void handle( long now )
            {
                //not to run if level is nul
                if( null == currentLevel ){return;}
               
                //getting delta
                delta = ( float ) ( ( now - pastTick ) / 1e9 ) ;
               
               update( delta );
               render();
               
               pastTick = now;
               
            }//
           
        };

its better not know why it works, that know why is not working
Offline philfrei
« Reply #1 - Posted 2018-09-12 21:32:15 »

Looks good to me!

Here are my two comments, based on still limited experience.

It hadn't occurred to me that at 60 fps, the individual frames might not be evenly spread out. I'm curious what the range of deltas will be. I've recently started work (part time) on a new game and when I get to the game loop, I will run some tests on this.

If the deltas are "close enough" then having each frame be an integer increment does significantly reduce the amount of computation involved per frame. As always, we have to try and weigh the trade-offs.

Second comment: so far, it seems to me that having separate update() and render() sections is may be a bit artificial with JavaFX. I'm curious what others think.

Let's say we have a model and a display object. "Updating" the model makes sense as a step. But suppose the image to be displayed is held in an ImageView. When we update the location coordinates of the ImageView, are we "updating" or are we "rendering"? Also, there are ways that graphical objects can be bound to the model layer, and thus not even require updating.

In any event, this seems quite good enough to get going. I'd be willing to assume that if further refinements are needed, they will make themselves known and won't be too difficult to refactor in.

music and music apps: http://adonax.com
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

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

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

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

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

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

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!