0

I'm programing a game with Java (Jogl, JInput). I'm not sure about my code. How to record keys strength? First I record a pair (keyName, millisTime) on any keypad's event. Then I try to update game's state with new key's value.

I think I have an error with the first part of the code.

                PositionButton pb = positionButtonList.get(comp.getName());
                System.out.println(comp.getName());
                pb.nanotimeEllapsed = System.nanoTime() - pb.startTime;
                pb.startTime = System.nanoTime() - pb.nanotimeEllapsed;


public void on(String compName, float value) {
    System.out.println(compName + "|" + value);

    if (positionButtonList.get(compName) == null) {
        System.exit(-1);
    }
    long move;
    System.out.println("Move intensity: "+(move = (long) (value * positionButtonList.get(compName).nanotimeEllapsed / 1000.0)));
    switch (compName) {
        case "Axe X":
            if (move > 0) {
                if (positionButtonList.get(compName) != null) {
                    positionUpdate.rotationDroite(move);

                }
            } else if (positionButtonList.get(compName) != null) {
                positionUpdate.rotationGauche(-move);
            }
            break;
        case "Axe Y":
            if (move > 0) {
                if (positionButtonList.get(compName) != null) {
                    positionUpdate.acc(move);

                }
            } else if (positionButtonList.get(compName) != null) {
                positionUpdate.dec(-move);
            }
            break;
    }
}

Full code: https://gitlab.com/LaboManu/Power-and-Damages/blob/master/src/be/manudahmen/emptycanvas/apps/darz/input/Joystick.java

manueldahmen
  • 71
  • 2
  • 6
  • What do you mean by "key strength"? – gouessej Apr 28 '17 at 11:36
  • I don't know exactly. But what I want to do is to record each movement of the keypad so the game will work "normally", normally: having a thread recording each movement and update the game position/character/action with the values provided with the keypad. The sample code provided by JInput tutorial seems to not work perfectly - in my case it doesn't work at all. – manueldahmen Apr 30 '17 at 17:03
  • You should look at the JInput integration within JogAmp's Ardor3D Continuation, it just works, it might help you to understand what is wrong in your own code. – gouessej May 02 '17 at 12:15

0 Answers0