Results 1 to 4 of 4
  1. #1
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Game loop ( FX )

    As we know, game loop is about to update game state. It is very required if game is action based.

    I have found animationTimer:

    Java Code:
    AnimationTimer animator = new AnimationTimer()
            {
                public void handle (long arg0) 
                {
                	int step = random.nextInt(50);
                	
                	movement.a = movement.a + 1;
                	
                	gem.setTranslateY (movement.a);
                	
                	
                	if ( step == 2) 
                	{           		
                		movement.a = movement.a + 10;
                		
                		gem. setTranslateX( 10 + movement.a );         		
                	}
                }
            };
            
            animator.start();
    Using animationTimer, I can actually make auto movement.
    Is it the end of game loop, or is it not game loop, its just animation?

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    387
    Rep Power
    4

    Default Re: Game loop ( FX )

    The animation timer can be used for many purposes. The handle() method is called in each frame while it is active. How many frames JavaFX actually renders is dependent on the complexity of your program, the max is about 60 frames/second.

  3. #3
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Re: Game loop ( FX )

    But in example i Tried to do loop manually to update:

    Java Code:
    for ( int a = 0; a<1; ) {
    
    // attempt to insert various items such as buttons, scenes, group ...
    
    }
    Once I tried to do loop like that, eclipse have frozen. Indeed animation timer is best loop.

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    387
    Rep Power
    4

    Default Re: Game loop ( FX )

    If you do not want that infinite loop to freeze your program you have to put it in a separate thread (which introduces a whole box of new issues).

    I personally like the Timeline better for animation or as game engine because it gives you more options, e.g. for frequency, etc.

Similar Threads

  1. Hangman Game loop
    By Grocerybag in forum New To Java
    Replies: 3
    Last Post: 11-07-2012, 02:57 AM
  2. Guessing Game Loop
    By co2balance in forum New To Java
    Replies: 4
    Last Post: 08-14-2012, 04:49 PM
  3. How to end loop for game?
    By javaboy2 in forum New To Java
    Replies: 5
    Last Post: 10-18-2011, 01:56 AM
  4. HiQ game ENDLESS LOOP HELP PLEASE !!
    By Bgreen7887 in forum New To Java
    Replies: 2
    Last Post: 10-08-2011, 01:27 AM
  5. [help] game loop
    By Fuzzier in forum Java Applets
    Replies: 3
    Last Post: 10-31-2009, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •