Reputation: 51
So, I'm trying to check my mouse position inside of my game window but my program doesn't update the x and y coordinates correctly. Instead, it only displays a static number for both x and y. I'm pretty sure I did set up Slick2D and lwjgl correctly as an empty black box with the FPS counter does appear when I run the application.
Anyways, the below code is displaying "x: -161 y:-1" for whatever reason. How would I fix this so that it displays the correct mouse position?
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class LogIn extends BasicGameState{
public String mouse;
public LogIn(int state){
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
g.setColor(Color.white);
g.drawString(mouse, 50, 50);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
int xpos = Mouse.getX();
int ypos = Mouse.getY();
mouse = "x: " + xpos + " y: " + ypos;
}
public int getID(){
return 1;
}
}
Upvotes: 0
Views: 2547
Reputation: 51
I have figured it out. I used the lwjgl.jar from the lwjgl-2.9.2 download folder and it worked. I guessed using the one that came with Slick2D was buggy or something. Maybe my set up was wrong from the start? Anyways, I got it to work.
Upvotes: 1
Reputation: 1148
Try this:
Input input = gc.getInput();
int xpos = input.getMouseX();
int ypos = input.getMouseY();
Upvotes: 1