0 Replies Latest reply: Nov 23, 2011 10:32 AM by 901830 RSS

    onkeypressed / onkeyreleased won't register

    901830
      Hi I am using Netbeans 6.9.1 with what I think is JavaFX 1.3.1 and I am having trouble getting my onkeypressed and/or onkeyreleased to work. Here is my simple test program that simply draws a cricle that should be able to be moved. Please ignore the excessive unused imports and variables within the keyevent function that have not been used yet.

      package gamepractice;

      import javafx.scene.text.Text;
      import javafx.scene.text.Font;
      import javafx.animation.Interpolator;
      import javafx.animation.Timeline;
      import javafx.scene.paint.Color;
      import javafx.scene.Scene;
      import javafx.scene.shape.Circle;
      import javafx.scene.shape.Line;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;
      import javafx.scene.Node;
      import javafx.scene.Group;
      import javafx.scene.control.Button;
      import java.lang.UnsupportedOperationException;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.input.KeyCode;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;

      /**
      * @author Benji
      */

      def draw = DrawEntities{};
      var xpos = 100;
      var ypos = 100;
      var upkey = false;
      var downkey = false;
      var leftkey = false;
      var rightkey = false;
      var blahhh = Circle {
           centerX: bind xpos, centerY: bind ypos
           radius: 40
           fill: Color.BLACK
      onKeyPressed:function(e: KeyEvent):Void{
      if (e.code == KeyCode.VK_DOWN) {
      downkey = true;
      } else if (e.code == KeyCode.VK_UP) {
      upkey = true;
      }else if (e.code == KeyCode.VK_LEFT) {
      leftkey = true;
      }else if (e.code == KeyCode.VK_RIGHT) {
      rightkey = true;
      }
      }
      onKeyReleased:function(e: KeyEvent):Void{
      if (e.code == KeyCode.VK_DOWN) {
      downkey = false;
      ypos = ypos -10;
      } else if (e.code == KeyCode.VK_UP) {
      upkey = false;
      ypos = ypos +10;
      }else if (e.code == KeyCode.VK_LEFT) {
      leftkey = false;
      xpos = xpos -10;
      }else if (e.code == KeyCode.VK_RIGHT) {
      rightkey = false;
      xpos = xpos +10;
      }
      }
      };
      Stage {
      title: "Testing"
      scene:
      Scene {
      width: 1200
      height: 650
      content:
      [
      blahhh
      ]
      }
      }

      Any help as to why my circle is drawn but will not move is appreciated. I tried searching online but no one seems to have a problem with these keyevents but me. Thanks, Mark