0

Heres the code for the KeyInput

    public void keyPressed(KeyEvent e) {

        int key = e.getKeyCode();

        for(int i = 0; i < handler.object.size(); i++) {
            GameObject tempObject = handler.object.get(i);

            if(tempObject.getId() == ID.Player) {
                //key events for player 1

                if(key == KeyEvent.VK_W) tempObject.setVelY(-5);
                if(key == KeyEvent.VK_A) tempObject.setVelX(-5);
                if(key == KeyEvent.VK_S) tempObject.setVelY(5);
                if(key == KeyEvent.VK_D) tempObject.setVelX(5);
            }



        }

    }

Heres the code for my velocities

        y += velY;

when I launch the program and press any assigned movement keys then my player dissapears entirely, any help?

Vaillancourt
  • 16,325
  • 17
  • 55
  • 61
  • Put a breakpoint on y += velY; and see what happens; likely, your player goes very fast and exits the bounds of your window. – Vaillancourt May 04 '20 at 16:32
  • ok so Ive added a breakpoint and the player moves very fast, any idea on a fix? – MatthewTGM May 04 '20 at 21:00
  • The obvious answer to this is "move it less fast", either by reducing the velocity, or the update rate, but you probably thought of it already. You can also try to constrain your player within the bounds of your window. I'm not familiar with the framework you're using, and you don't tell us what it is. It's hard to see the big picture of what you're trying to do. – Vaillancourt May 04 '20 at 21:06

0 Answers0