Class GameScreen

java.lang.Object
nl.saxion.gameapp.screens.GameScreen
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor, com.badlogic.gdx.Screen, com.badlogic.gdx.utils.Disposable
Direct Known Subclasses:
GameScreenWithHUD

public abstract class GameScreen extends Object implements com.badlogic.gdx.Screen, com.badlogic.gdx.InputProcessor
An abstract base class representing a single screen in the game.

This class implements both the Screen and InputProcessor interfaces from LibGDX, providing default (mostly empty) implementations for all required methods.

Subclasses are expected to override the render(float) method and optionally handle input events if desired.

Usage example:

 public class MainMenuScreen extends GameScreen {
     @Override
     public void render(float delta) {
         // Your rendering logic here
     }
 }
 
This design allows students to focus on game-specific logic without having to re-implement all of the required LibGDX interface methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called when the screen is disposed of and its resources should be released.
    boolean
    keyDown(int keycode)
    Called when a key is pressed.
    boolean
    keyTyped(char character)
    Called when a key is typed (pressed and released).
    boolean
    keyUp(int keycode)
    Called when a key is released.
    boolean
    mouseMoved(int x, int y)
    Called when the mouse is moved without any buttons being pressed.
    void
    Called when the game is paused.
    abstract void
    render(float delta)
    Called once per frame to render the screen.
    void
    resize(int width, int height)
    Called when the screen size changes.
    void
    Called when the game is resumed after being paused.
    boolean
    scrolled(float amountX, float amountY)
    Called when the user scrolls using the mouse wheel or a trackpad.
    boolean
    touchCancelled(int screenX, int screenY, int pointer, int button)
    Called when an ongoing touch is canceled (e.g., due to focus loss or system gesture).
    boolean
    touchDown(int x, int y, int pointer, int button)
    Called when a pointer (touch or mouse) is pressed down.
    boolean
    touchDragged(int x, int y, int pointer)
    Called when a pointer (touch or mouse) is dragged across the screen.
    boolean
    touchUp(int x, int y, int pointer, int button)
    Called when a pointer (touch or mouse) is released.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.badlogic.gdx.Screen

    hide, show
  • Constructor Details

    • GameScreen

      public GameScreen()
  • Method Details

    • render

      public abstract void render(float delta)
      Called once per frame to render the screen.

      This is the only abstract method — subclasses must implement it to define what happens every frame.

      Specified by:
      render in interface com.badlogic.gdx.Screen
      Parameters:
      delta - the time in seconds since the last frame was rendered
    • resize

      public void resize(int width, int height)
      Called when the screen size changes.

      Most games handle this via a camera and viewport system, so this method is left empty by default.

      Specified by:
      resize in interface com.badlogic.gdx.Screen
      Parameters:
      width - the new width of the screen in pixels
      height - the new height of the screen in pixels
    • pause

      public void pause()
      Called when the game is paused.

      This might happen when the app loses focus or is minimized.

      Specified by:
      pause in interface com.badlogic.gdx.Screen
    • resume

      public void resume()
      Called when the game is resumed after being paused.
      Specified by:
      resume in interface com.badlogic.gdx.Screen
    • dispose

      public void dispose()
      Called when the screen is disposed of and its resources should be released.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
      Specified by:
      dispose in interface com.badlogic.gdx.Screen
    • keyDown

      public boolean keyDown(int keycode)
      Called when a key is pressed.
      Specified by:
      keyDown in interface com.badlogic.gdx.InputProcessor
      Parameters:
      keycode - the key code of the pressed key
      Returns:
      false to indicate the event was not handled
    • keyUp

      public boolean keyUp(int keycode)
      Called when a key is released.
      Specified by:
      keyUp in interface com.badlogic.gdx.InputProcessor
      Parameters:
      keycode - the key code of the released key
      Returns:
      false to indicate the event was not handled
    • keyTyped

      public boolean keyTyped(char character)
      Called when a key is typed (pressed and released).
      Specified by:
      keyTyped in interface com.badlogic.gdx.InputProcessor
      Parameters:
      character - the character corresponding to the typed key
      Returns:
      false to indicate the event was not handled
    • touchDown

      public boolean touchDown(int x, int y, int pointer, int button)
      Called when a pointer (touch or mouse) is pressed down.
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      Parameters:
      x - the x-coordinate of the touch
      y - the y-coordinate of the touch
      pointer - the pointer index (for multi-touch)
      button - the button pressed (for mouse input)
      Returns:
      false to indicate the event was not handled
    • touchUp

      public boolean touchUp(int x, int y, int pointer, int button)
      Called when a pointer (touch or mouse) is released.
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
      Parameters:
      x - the x-coordinate of the release
      y - the y-coordinate of the release
      pointer - the pointer index (for multi-touch)
      button - the button released (for mouse input)
      Returns:
      false to indicate the event was not handled
    • touchDragged

      public boolean touchDragged(int x, int y, int pointer)
      Called when a pointer (touch or mouse) is dragged across the screen.
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
      Parameters:
      x - the current x-coordinate
      y - the current y-coordinate
      pointer - the pointer index (for multi-touch)
      Returns:
      false to indicate the event was not handled
    • mouseMoved

      public boolean mouseMoved(int x, int y)
      Called when the mouse is moved without any buttons being pressed.
      Specified by:
      mouseMoved in interface com.badlogic.gdx.InputProcessor
      Parameters:
      x - the new x-coordinate of the mouse
      y - the new y-coordinate of the mouse
      Returns:
      false to indicate the event was not handled
    • scrolled

      public boolean scrolled(float amountX, float amountY)
      Called when the user scrolls using the mouse wheel or a trackpad.
      Specified by:
      scrolled in interface com.badlogic.gdx.InputProcessor
      Parameters:
      amountX - horizontal scroll amount
      amountY - vertical scroll amount
      Returns:
      false to indicate the event was not handled
    • touchCancelled

      public boolean touchCancelled(int screenX, int screenY, int pointer, int button)
      Called when an ongoing touch is canceled (e.g., due to focus loss or system gesture).
      Specified by:
      touchCancelled in interface com.badlogic.gdx.InputProcessor
      Parameters:
      screenX - the x-coordinate of the touch
      screenY - the y-coordinate of the touch
      pointer - the pointer index (for multi-touch)
      button - the button involved (if any)
      Returns:
      false to indicate the event was not handled