title: JavaFX: Moving image with arrow keys and spacebar
body: <p>I'm trying to make a little game like Space Invaders. I'm using JavaFX with Netbeans 6.9 and couldn't find an answer elsewhere, so I thought I'ld just ask here.</p>
  
  <p>I have an image of a space ship, which I would like to move using my arrow keys. When I press spacebar it should shoot a missile. The missile can destroy a meteorite.</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>import javafx.stage.Stage;
  import javafx.scene.Scene;
  import javafx.scene.paint.Color;
  import javafx.scene.image.ImageView;
  import javafx.scene.image.Image;
  import javafx.animation.Timeline;
  import javafx.animation.Interpolator;
  
  var x: Number;
  Timeline {
      repeatCount: Timeline.INDEFINITE
      autoReverse: true
      keyFrames: [
      at (0s) {x =&gt; 500.0},
      at (10s) {x =&gt; -100.0 tween Interpolator.LINEAR}
      ]
  }.play();
  
  Stage {
  title: "Shoot"
  scene: Scene {
      fill: Color.BLACK
      width: 800
      height: 500
      content: [
          ImageView {
              x: 500 y: 25
              image: Image {
                  url: "{__DIR__}earth.jpg";
              }
          }
          ImageView {
              translateX: bind x
              x: 150 y: 300
              image: Image {
                  url: "{__DIR__}meteorite.png";
              }
          }
          ImageView {
              x: 400 y: 450
              image: Image {
                  url: "{__DIR__}spaceship.png";
              }
          }
      ]
  }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>