0

我只是在玩一些 java 编程,所以当我按下一个键时,我想要一张图片在屏幕上移动。我怎么会收到一条消息说“Thu Jun 14 13:14:23 EDT 2012 INFO:Controllers not available”这是我在这个页面上的代码

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;}
    }
}

现在,如果我要像这样运行它,对象会在同一个位置说,但是如果我只有一个 if 语句,对象将在我不按键的情况下向方向移动,所以如果我有if(input.isKeyDown(Input.KEY_UP)); {sunY -= 1;}应用程序启动太阳向上移动并离开屏幕。我做错了什么导致这种情况发生?

4

1 回答 1

2

尝试将其更改 if(input.isKeyDown(Input.KEY_UP)); {sunY -= 1;} 为此:D

if(input.isKeyDown(Input.KEY_UP)) {sunY -= 1;}
于 2012-06-14T17:36:36.363 回答