0

如何调用 if 语句(或任何其他函数)而不再次调用它,直到它完成执行?我有一个调用另一个函数(在另一个类中)的更新函数,但是因为它执行每个更新,所以用户没有时间实际完成 IF 语句(if 语句依赖于用户输入),因此它什么也不返回或只有第一部分。

代码(更新在哪里):

public void Update(){
    if(Mouse.isButtonDown(0)){
        changeTile();
    }
    while(Keyboard.next()){
        if(Keyboard.getEventKey() == Keyboard.KEY_RIGHT && Keyboard.getEventKeyState()){
            moveIndex();
        }
        if(Keyboard.getEventKey() == Keyboard.KEY_LEFT && Keyboard.getEventKeyState()){
            moveIndexBack();
        }
    }
}

改变瓷砖功能:

    public void changeTile(){
    boolean start = true;

    if(start){
        while(Mouse.next()){
        if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState()){
                    //system uses tileTypes because player textures are tiletypes itself, so in the end we can let them swim by changing tiletypes
                    int xCoord = (int) Math.floor(Mouse.getX() / 64);
                    int yCoord = (int) Math.floor((HEIGHT - Mouse.getY() - 1) / 64);
                    tileType tile1 = map[xCoord][yCoord].getType();
                    System.out.println("first tile is set to:" + tile1);
                    start = false;
            }
        }
    }

    if(!start){
        while(Mouse.next()){
            if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState()){
                int xCoord2 = (int) Math.floor(Mouse.getX() / 64);
                int yCoord2 = (int) Math.floor((HEIGHT - Mouse.getY() - 1) / 64);
                tileType tile2 = map[xCoord2][yCoord2].getType();
                System.out.println("second tile is set to:" + tile2);
            }
        }
    }
4

0 回答 0