java - Incorrect value being returned from static method -


i'm having issue getting mouse input in lwjgl. here's code input:

public class mousebutinput extends glfwmousebuttoncallback {      public static boolean[] buttons = new boolean[65536];      public static boolean isbuttonpressed(int button) {         return buttons[button];     }      public static boolean isbuttonpressedrelease(int button) {         boolean ispressed = buttons[button];         if (ispressed) system.out.println("test 1");         buttons[button] = false;         if (ispressed) system.out.println("test 2");         return ispressed;     }      @override     public void invoke(long window, int button, int action, int mods) {         if (action == glfw_press) buttons[button] = true;         else buttons[button] = false;     } } 

i having issue when clicked once, isbuttonpressed() method return true next 5-10 updates because that's how long button held down. created isbuttonpressedrelease() method return true if button pressed , set button's value in buttons false, wouldn't return true next update. problem is, never seems return true. put in few print lines test if ispressed true before return it, was. if switch using isbuttonpressed() method works expected.

not sure i'm missing here... guess has mixing static , non-static methods/variables?

also, here call method from:

public void update() {     ishover = (aabb.intersectspoint(mouseposinput.pos.x, mouseposinput.pos.y)) ? true : false;     if (mousebutinput.isbuttonpressedrelease(glfw_mouse_button_1) && ishover && onclick != null) {         actionevent evt = new actionevent(this, actionevent.action_performed, "button clicked.");         onclick.actionperformed(evt);     } else {     } } 


edit

for clarification, when application launched following code run:

private glfwmousebuttoncallback buttoncallback; ... glfwsetkeycallback(window, keycallback = new keyinput()); 

now, invoke automatically called each time mouse button pressed. not using isbuttonpressed(), isbuttonpressedrelease(). 2 methods used outside of mousebutinput class see if key pressed, difference isbuttonpressedrelease needs go buttons array , set value button checking false.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -