0

我在 Google 中找不到答案,但有Mouse Over AreaforSlick2D吗?谷歌只是给了我的Java结果 MouseOverArea。我只想知道是否有MouseOverAreafor Slick2D,以及它的外观。

这是我的代码:

Game班级

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Game extends StateBasedGame {

public static final String gamename = "Life - Alpha";
public static int splash = 0;
public static int menu = 1;
public static int loading = 2;
public static int play= 3;

public Game(String gamename) {
    super(gamename);
}

public void initStatesList(GameContainer gc) throws SlickException {
    this.addState(new SplashScreen (splash));
    this.addState(new Menu (menu));
    this.addState(new Exit (exit));
    this.addState(new Loading (loading));
    this.addState(new Play(play));
    this.enterState(0);
}

public static void main(String[] args) {

    AppGameContainer app;
    try {
        app = new AppGameContainer(new Game(gamename));
        app.setDisplayMode(800, 600, false);
        app.start();
    } catch (SlickException e) {
        e.printStackTrace();
    }

}
}

SplashScreen班级:

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class SplashScreen extends BasicGameState {
Image splash;

private int elapsedTime;
private final int DELAY = 3000;

public SplashScreen(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    splash = new Image("res/SplashScreen.png");

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
    g.drawImage(splash, 0, 0);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(1);
    }
}

public int getID() {
    return 0;
}

}

Menu班级:

import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Menu extends BasicGameState {

public Menu(int state) {

}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Background.png");
    g.drawImage(background, 0, 0);

    Image logo = new Image("res/Logo.png");
    g.drawImage(logo, 275, 50);

    Image playButton = new Image("res/Play button.png");
    g.drawImage(playButton, 210, 250);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {     

    Input input = gc.getInput();
    int xpos = Mouse.getX();
    int ypos = Mouse.getY();


    if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {

        if (input.isMousePressed(0)) {
            sbg.enterState(2);
        }
                    //I want to put the Slick2D MouseOverArea code here...
                    //So then when I put the mouse over the playButton, something will display.
    }
}

public int getID() {
    return 1;
}

}

Loading班级:

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Loading extends BasicGameState {

private int elapsedTime;
private final int DELAY = 5000;

public Loading(int state) {
}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

}

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    Image background = new Image("res/Back.png");
    g.drawImage(background, 0, 0);

    Image loading = new Image("res/Loading.png");
    g.drawImage(loading, 210, 150);

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    elapsedTime += delta;

    if(elapsedTime >= DELAY) {
        sbg.enterState(3);
    }
}
public int getID() {
    return 2;
}

}

Play班级:

我还在努力……但是这个类不需要MouseOverArea,这个Menu需要。


这就是我上面的代码。我只需要一个MouseOverAreafor Slick2D。谷歌没有帮助。希望你能。

另外,你能有一个TextFieldinSlick2D吗?我不知道我能不能。我知道在正常情况Java下你可以,但你可以Slick2D吗?

如果有任何错误,请不要担心,我可以修复它们。

谢谢

4

1 回答 1

1

代码不是放在这里的吗?

if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {
        //mouseover
        if (input.isMousePressed(0)) {
            sbg.enterState(2);
        }

    }
}
于 2013-11-29T01:08:03.620 回答