Package nl.saxion.gameapp.screens
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 -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Called when the screen is disposed of and its resources should be released.booleankeyDown(int keycode) Called when a key is pressed.booleankeyTyped(char character) Called when a key is typed (pressed and released).booleankeyUp(int keycode) Called when a key is released.booleanmouseMoved(int x, int y) Called when the mouse is moved without any buttons being pressed.voidpause()Called when the game is paused.abstract voidrender(float delta) Called once per frame to render the screen.voidresize(int width, int height) Called when the screen size changes.voidresume()Called when the game is resumed after being paused.booleanscrolled(float amountX, float amountY) Called when the user scrolls using the mouse wheel or a trackpad.booleantouchCancelled(int screenX, int screenY, int pointer, int button) Called when an ongoing touch is canceled (e.g., due to focus loss or system gesture).booleantouchDown(int x, int y, int pointer, int button) Called when a pointer (touch or mouse) is pressed down.booleantouchDragged(int x, int y, int pointer) Called when a pointer (touch or mouse) is dragged across the screen.booleantouchUp(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, waitMethods 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:
renderin interfacecom.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:
resizein interfacecom.badlogic.gdx.Screen- Parameters:
width- the new width of the screen in pixelsheight- 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:
pausein interfacecom.badlogic.gdx.Screen
-
resume
public void resume()Called when the game is resumed after being paused.- Specified by:
resumein interfacecom.badlogic.gdx.Screen
-
dispose
public void dispose()Called when the screen is disposed of and its resources should be released.- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable- Specified by:
disposein interfacecom.badlogic.gdx.Screen
-
keyDown
public boolean keyDown(int keycode) Called when a key is pressed.- Specified by:
keyDownin interfacecom.badlogic.gdx.InputProcessor- Parameters:
keycode- the key code of the pressed key- Returns:
falseto indicate the event was not handled
-
keyUp
public boolean keyUp(int keycode) Called when a key is released.- Specified by:
keyUpin interfacecom.badlogic.gdx.InputProcessor- Parameters:
keycode- the key code of the released key- Returns:
falseto indicate the event was not handled
-
keyTyped
public boolean keyTyped(char character) Called when a key is typed (pressed and released).- Specified by:
keyTypedin interfacecom.badlogic.gdx.InputProcessor- Parameters:
character- the character corresponding to the typed key- Returns:
falseto 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:
touchDownin interfacecom.badlogic.gdx.InputProcessor- Parameters:
x- the x-coordinate of the touchy- the y-coordinate of the touchpointer- the pointer index (for multi-touch)button- the button pressed (for mouse input)- Returns:
falseto 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:
touchUpin interfacecom.badlogic.gdx.InputProcessor- Parameters:
x- the x-coordinate of the releasey- the y-coordinate of the releasepointer- the pointer index (for multi-touch)button- the button released (for mouse input)- Returns:
falseto 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:
touchDraggedin interfacecom.badlogic.gdx.InputProcessor- Parameters:
x- the current x-coordinatey- the current y-coordinatepointer- the pointer index (for multi-touch)- Returns:
falseto 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:
mouseMovedin interfacecom.badlogic.gdx.InputProcessor- Parameters:
x- the new x-coordinate of the mousey- the new y-coordinate of the mouse- Returns:
falseto 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:
scrolledin interfacecom.badlogic.gdx.InputProcessor- Parameters:
amountX- horizontal scroll amountamountY- vertical scroll amount- Returns:
falseto 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:
touchCancelledin interfacecom.badlogic.gdx.InputProcessor- Parameters:
screenX- the x-coordinate of the touchscreenY- the y-coordinate of the touchpointer- the pointer index (for multi-touch)button- the button involved (if any)- Returns:
falseto indicate the event was not handled
-