Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (794)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
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 2627 times)
0 Members and 1 Guest are viewing this topic.
Offline pavul

Senior 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:

 gameThread = new AnimationTimer() 

            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 );
               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:
Pages: [1]
  ignore  |  Print  

hadezbladez (3129 views)
2018-11-16 13:46:03

hadezbladez (1139 views)
2018-11-16 13:41:33

hadezbladez (3096 views)
2018-11-16 13:35:35

hadezbladez (620 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (4603 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

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 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!