public class GameTimer
extends com.badlogic.gdx.scenes.scene2d.ui.Label
Modifier and Type | Field and Description |
---|---|
private int |
minutes
Holds the number of minutes that the timer is currently clocked to
|
private com.badlogic.gdx.graphics.Color |
pauseColour
Holds the colour that the timer's label assumes while it's stalled
|
private com.badlogic.gdx.graphics.Color |
runColour
Holds the colour that the timer's label assumes while it's running
|
private int |
seconds
Holds the number of seconds that the timer is currently clocked to
|
private java.lang.Runnable |
terminalMethod
Holds custom-set method to be executed when the timer reaches zero
|
private com.badlogic.gdx.utils.Timer |
timer
Core timer object that provides the main timing functionality
|
Constructor and Description |
---|
GameTimer(int minutes,
int seconds,
TTFont font,
com.badlogic.gdx.graphics.Color runColour)
Sets up the timer for later use
Overloaded constructor that forgoes setting a terminal method and renders the timer gray when paused
|
GameTimer(int minutes,
int seconds,
TTFont font,
com.badlogic.gdx.graphics.Color runColour,
com.badlogic.gdx.graphics.Color pauseColour)
Sets up the timer for later use
Overloaded constructor that forgoes setting a terminal method
|
GameTimer(int minutes,
int seconds,
TTFont font,
com.badlogic.gdx.graphics.Color runColour,
com.badlogic.gdx.graphics.Color pauseColour,
java.lang.Runnable end)
Sets up the timer for later use
Works by instantiating the timer as label, changing that label's appearance to reflect the provided time and
setting up the label's internal Timer object to run the provided terminal method when the "minutes" and "seconds"
variables both reach 0 (after being changed enough times following each Timer interval)
|
GameTimer(int seconds,
TTFont font,
com.badlogic.gdx.graphics.Color runColour)
Sets up the timer for later use
Overloaded constructor that sets the timer based on a total number of seconds (rather than a combination
of minutes and seconds), forgoes setting a terminal method and renders the timer gray when paused
|
GameTimer(int seconds,
TTFont font,
com.badlogic.gdx.graphics.Color runColour,
com.badlogic.gdx.graphics.Color pauseColour)
Sets up the timer for later use
Overloaded constructor that sets the timer based on a total number of seconds (rather than a combination
of minutes and seconds) and forgoes setting a terminal method
|
GameTimer(int seconds,
TTFont font,
com.badlogic.gdx.graphics.Color runColour,
com.badlogic.gdx.graphics.Color pauseColour,
java.lang.Runnable end)
Sets up the timer for later use
Overloaded constructor that sets the timer based on a total number of seconds (rather than a combination
of minutes and seconds)
|
GameTimer(int seconds,
TTFont font,
com.badlogic.gdx.graphics.Color runColour,
java.lang.Runnable end)
Sets up the timer for later use
Overloaded constructor that sets the timer based on a total number of seconds (rather than a combination
of minutes and seconds) and renders the timer gray when paused
|
Modifier and Type | Method and Description |
---|---|
private void |
decrement()
Decrements the internal timer by 1 second upon being called
|
java.lang.Runnable |
getTerminalMethod()
Returns the timer's terminal method inside of a Runnable object
|
void |
increment()
Increments the internal timer by 1 second upon being called
This is required to circumvent a bug that causes the timer to lose a second whenever it's started from a state
where it has previously been stopped
|
int |
minutes()
Returns the number of minutes currently clocked on the timer
Changed in Assessment 3 (Integer -> int)
|
void |
runTerminalMethod()
Runs the timer's terminal method upon being called
This can be called at any time
|
int |
seconds()
Returns the number of seconds currently clocked on the timer (within the current minute)
Changed in assessment 3 (Integer -> int)
|
void |
setTerminalMethod(java.lang.Runnable terminalMethod)
Sets a new method for the timer to execute when it hits 0
|
void |
setTime(int minutes,
int seconds)
Clocks the timer to the provided time
Specifically changes the internal minutes/seconds variables as necessary and updates the core label's
appearance to visualise the new timer provided
Changed in Assessment 3
|
void |
start()
Starts the timer (and changes the timer's colour appropriately)
|
void |
stop()
Stops the timer (and changes the timer's colour appropriately)
Changed in Assessment 3 (to reset back to 0:0)
|
draw, getBitmapFontCache, getFontScaleX, getFontScaleY, getGlyphLayout, getLabelAlign, getLineAlign, getPrefHeight, getPrefWidth, getStyle, getText, invalidate, layout, setAlignment, setAlignment, setEllipsis, setEllipsis, setFontScale, setFontScale, setFontScaleX, setFontScaleY, setStyle, setText, setWrap, textEquals, toString
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
act, addAction, addCaptureListener, addListener, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, fire, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasParent, hit, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
private int minutes
private int seconds
private com.badlogic.gdx.utils.Timer timer
private java.lang.Runnable terminalMethod
private com.badlogic.gdx.graphics.Color runColour
private com.badlogic.gdx.graphics.Color pauseColour
public GameTimer(int minutes, int seconds, TTFont font, com.badlogic.gdx.graphics.Color runColour, com.badlogic.gdx.graphics.Color pauseColour, java.lang.Runnable end)
minutes
- The number of minutes to which the timer should initially be clockedseconds
- The number of seconds to which the timer should initially be clockedfont
- The font of the timer's visual interfacerunColour
- The colour that the timer will assume while it's runningpauseColour
- The colour that the timer will assume while it's pausedend
- The runnable subroutine to be executed when the timer reaches zeropublic GameTimer(int minutes, int seconds, TTFont font, com.badlogic.gdx.graphics.Color runColour, com.badlogic.gdx.graphics.Color pauseColour)
minutes
- The number of minutes to which the timer should initially be clockedseconds
- The number of seconds to which the timer should initially be clockedfont
- The font of the timer's visual interfacerunColour
- The colour that the timer will assume while it's runningpauseColour
- The colour that the timer will assume while it's pausedpublic GameTimer(int seconds, TTFont font, com.badlogic.gdx.graphics.Color runColour, com.badlogic.gdx.graphics.Color pauseColour, java.lang.Runnable end)
seconds
- The number of seconds to which the timer should initially be clockedfont
- The font of the timer's visual interfacerunColour
- The colour that the timer will assume while it's runningpauseColour
- The colour that the timer will assume while it's pausedend
- The runnable subroutine to be executed when the timer reaches zeropublic GameTimer(int seconds, TTFont font, com.badlogic.gdx.graphics.Color runColour, com.badlogic.gdx.graphics.Color pauseColour)
seconds
- The number of seconds to which the timer should initially be clockedfont
- The font of the timer's visual interfacerunColour
- The colour that the timer will assume while it's runningpauseColour
- The colour that the timer will assume while it's pausedpublic GameTimer(int minutes, int seconds, TTFont font, com.badlogic.gdx.graphics.Color runColour)
minutes
- The number of minutes to which the timer should initially be clockedseconds
- The number of seconds to which the timer should initially be clockedfont
- The font of the timer's visual interfacerunColour
- The colour that the timer will assume while it's runningpublic GameTimer(int seconds, TTFont font, com.badlogic.gdx.graphics.Color runColour, java.lang.Runnable end)
seconds
- The number of seconds to which the timer should initially be clockedfont
- The font of the timer's visual interfacerunColour
- The colour that the timer will assume while it's runningend
- The runnable subroutine to be executed when the timer reaches zeropublic GameTimer(int seconds, TTFont font, com.badlogic.gdx.graphics.Color runColour)
seconds
- The number of seconds to which the timer should initially be clockedfont
- The font of the timer's visual interfacerunColour
- The colour that the timer will assume while it's runningpublic void setTime(int minutes, int seconds)
minutes
- The number of minutes to which the timer should be clockedseconds
- The number of seconds to which the timer should be clockedprivate void decrement()
public void increment()
public int minutes()
public int seconds()
public void start()
public void stop()
public java.lang.Runnable getTerminalMethod()
public void setTerminalMethod(java.lang.Runnable terminalMethod)
terminalMethod
- The timer's new terminal methodpublic void runTerminalMethod()