Slick2d StateBasedGame - WindowListener

时间:2013-11-03 12:59:56

标签: slick2d

我有一个基于状态的游戏,我需要在其中一个状态中实现一个WindowListener。我怎么做?在网上找不到任何东西。

1 个答案:

答案 0 :(得分:0)

你没有在网上找到任何东西的原因是因为Slick2d没有提供自己的WindowListener!你可能会想到的WindowListener是核心java的一部分: http://docs.oracle.com/javase/7/docs/api/java/awt/event/WindowListener.html

对于java的WindowListener,有很多在线教程,但大多数都需要使用像Swing这样的东西才有用。

我强烈建议您在update()函数中使用它来检查窗口的状态。它将满足Slick2d中的大多数需求(例如,我使用它来检测暂停游戏,因为窗口失去焦点):

public void update(GameContainer container, StateBasedGame game, int delta)
        throws SlickException {
    if(!container.hasFocus()){
        //Pause the game here.