Class ScreenManager

java.lang.Object
de.gurkenlabs.litiengine.gui.screens.ScreenManager

public final class ScreenManager
extends java.lang.Object
The ScreenManager holds instances of all available screens and handles whenever a different Screen should be shown to the player. It provides the currently active Screen for the Game’s RenderComponent which calls the Screen.render(Graphics2D) method on every tick of the RenderLoop. Overwriting this method provides the ability to define a customized render pipeline that suits the need of a particular Screen implementation. With the GameScreen, the LITIENGINE provides a simple default Screen implementation that renders the current Environment and all its GuiComponents.
See Also:
Screen, RenderComponent, GameScreen, GuiComponent.render(java.awt.Graphics2D)
  • Constructor Summary

    Constructors 
    ConstructorDescription
    ScreenManager()
    You should never call this manually! Instead use the Game.screens() instance.
  • Method Summary

    Modifier and TypeMethodDescription
    voidadd​(Screen screen)
    Adds the specified screen instance to the manager.
    voidaddScreenChangedListener​(ScreenChangedListener listener)
    Adds the specified screen changed listener to receive events when the current screen was changed.
    Screencurrent()
    Gets the currently active screen that is being rendered by the RenderComponent.
    voiddisplay​(Screen screen)
    Displays the specified screen by setting
    voiddisplay​(java.lang.String screenName)
    Displays the Screen with the specified name.
    Screenget​(java.lang.String screenName)
    Gets the screen by its name.
    java.util.Collection<Screen>getAll()
    Gets all screens of the game.
    intgetChangeCooldown()
    Gets the screen change cooldown which is used to ensure that screens cannot be switched too quickly while the game is running.
    voidremove​(Screen screen)
    Removes the specified screen instance from the manager.
    voidremoveScreenChangedListener​(ScreenChangedListener listener)
    Removes the specified screen changed listener.
    voidsetChangeCooldown​(int changeCooldown)
    Sets the cooldown for changing screens.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ScreenManager

      public ScreenManager()

      You should never call this manually! Instead use the Game.screens() instance.

      See Also:
      Game.screens()
  • Method Details

    • addScreenChangedListener

      public void addScreenChangedListener​(ScreenChangedListener listener)
      Adds the specified screen changed listener to receive events when the current screen was changed.
      Parameters:
      listener - The listener to add.
    • removeScreenChangedListener

      public void removeScreenChangedListener​(ScreenChangedListener listener)
      Removes the specified screen changed listener.
      Parameters:
      listener - The listener to remove.
    • add

      public void add​(Screen screen)
      Adds the specified screen instance to the manager.
      Parameters:
      screen - The screen to add.
    • remove

      public void remove​(Screen screen)
      Removes the specified screen instance from the manager.
      Parameters:
      screen - The screen to remove.
    • display

      public void display​(Screen screen)
      Displays the specified screen by setting
      Parameters:
      screen - The screen to be displayed.
    • display

      public void display​(java.lang.String screenName)
      Displays the Screen with the specified name.
      Parameters:
      screenName - The name of the screen to be displayed.
    • get

      public Screen get​(java.lang.String screenName)
      Gets the screen by its name.
      Parameters:
      screenName - The name of the screen.
      Returns:
      The
    • getAll

      public java.util.Collection<Screen> getAll()
      Gets all screens of the game.
      Returns:
      All screens that have been previously added to this instance.
      See Also:
      add(Screen)
    • current

      public Screen current()
      Gets the currently active screen that is being rendered by the RenderComponent.
      Returns:
      The currently active screen.
      See Also:
      GameWindow.getRenderComponent(), RenderComponent.render()
    • getChangeCooldown

      public int getChangeCooldown()
      Gets the screen change cooldown which is used to ensure that screens cannot be switched too quickly while the game is running.
      Returns:
      The current change timeout for screens.
      See Also:
      DEFAULT_CHANGE_COOLDOWN, Game.hasStarted()
    • setChangeCooldown

      public void setChangeCooldown​(int changeCooldown)
      Sets the cooldown for changing screens.
      Parameters:
      changeCooldown - The cooldown for changing screens.