I am just playing around with some java programming and so I wanted a picture to move around the screen when I press a key. How ever I get a message saying “Thu Jun 14 13:14:23 EDT 2012 INFO:Controllers not available” this is the code I have for this page
public class Menu extends BasicGameState
{
Image sun;
int sunX = 200;
int sunY = 200;
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException
{
sun = new Image("res/sun.png");
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException
{
g.drawImage(sun, sunX, sunY);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException
{
Input input = gc.getInput();
if(input.isKeyDown(Input.KEY_UP)); {sunY -= 1;}
if(input.isKeyDown(Input.KEY_DOWN)); {sunY += 1;}
if(input.isKeyDown(Input.KEY_LEFT)); {sunX -= 1;}
if(input.isKeyDown(Input.KEY_RIGHT)); {sunX += 1;}
}
}
Right now if I was to run it like that the object will say in the same spot, but if I only have one of if statements object will move int the direction with out me pressing a key so if I have if(input.isKeyDown(Input.KEY_UP)); {sunY -= 1;} as soon as the app starts the sun moves up and off the screen. What have I done wrong for this to happen?
try changing this
if(input.isKeyDown(Input.KEY_UP)); {sunY -= 1;}to this 😀