Sunday, January 18, 2015

Anansi: Player Ship


Now that we have a scrolling background, we can add the player's ship. The code is very similar to the background code.

Create the player ship:

ImageView playerShip;

Create a layer for the ship:

Pane playfieldLayer;

Add the playfield layer to the scene:


playfieldLayer = new Pane();
...   
root.getChildren().add( playfieldLayer);

Load the player ship and add it to the scene. We position it in the horizontally centered and at 70% vertically:

  // player ship
  // --------------------------------
  playerShip = new ImageView( getClass().getResource( "assets/vehicles/anansi.png").toExternalForm());
  
  // center horizontally, position at 70% vertically
  playerShip.relocate( (SCENE_WIDTH - playerShip.getImage().getWidth()) / 2.0, SCENE_HEIGHT * 0.7);
  
  // add to playfield layer
  playfieldLayer.getChildren().add( playerShip);


With the added player ship the game looks like this:






As with the background feel free to use any of your resources for the player ship.

No comments:

Post a Comment