Showing posts with label 2d. Show all posts
Showing posts with label 2d. Show all posts

Sunday, January 18, 2015

Anansi: The Game Loop


The game we create is a 2D scrolling sh'm'up. So we need a game loop with gives us events at a given frame rate. There are various solutions to this, but we want to keep it simple for now. So the current choice for the game loop is an AnimationTimer.

The game loop basically looks like this:

  
package game;
 
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class Main extends Application {
 
 private double SCENE_WIDTH = 400;
 private double SCENE_HEIGHT = 800;
 
 private AnimationTimer timer;
 
 
 @Override
 public void start(Stage primaryStage) {
  try {

   // create root node
   Group root = new Group();
   
   // create scene
   Scene scene = new Scene( root, SCENE_WIDTH,SCENE_HEIGHT);
   
   // show stage
   primaryStage.setScene(scene);
   primaryStage.show();

   // start the game
   gameLoop();
   
  } catch(Exception e) {
   e.printStackTrace();
  }
 }

 private void gameLoop() {

  // game loop
        timer = new AnimationTimer() {
            @Override
            public void handle(long l) {
            
             // do something
             
            }
 
        };
        
        timer.start();
        
 }
 
 public static void main(String[] args) {
  launch(args);
 }
}

The AnimationTimer runs at 60 fps. Everything we do inside runs 60 times a second, so we need to be careful about the performance in that loop.

Anansi: Chapter 1: A Prototype


The game we want to create is called "Anansi". Anansi is the helicopter from the game Enemy Territory: Quake Wars.

ET:QW is a 1st person shooter and what we do has nothing to do with the game itself nor with the creators of the game. The assets we use are created using screenshots of the game. But you can use whatever you prefer, we keep that part generic. You could include Google Maps with a scrolling map of the player's location, so you could defend your home town from an alien invasion.

What we like to find out with our prototype:

  • Can we implement a 2D vertically scrolling shoot'em'up with JavaFX?
  • How easy is it to create a game? I prefer Rapid Application Development.
  • Do we need 3rd party libraries or is JavaFX sufficient?
  • How does the game perform with a lot of stuff happening on the screen?
  • The amount of time to create the prototype.
  • ...

Let's get some answers to these questions.

To be continued ... and keep on coding!