Package com.tenio.engine.heartbeat
Class AbstractHeartBeat
- java.lang.Object
-
- com.tenio.logger.AbstractLogger
-
- com.tenio.engine.heartbeat.AbstractHeartBeat
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.util.concurrent.Callable<java.lang.Void>
,java.util.EventListener
- Direct Known Subclasses:
ECSHeartBeat
public abstract class AbstractHeartBeat extends AbstractLogger implements java.util.concurrent.Callable<java.lang.Void>, java.awt.event.ActionListener
The game loop is the overall flow control for the entire game program. It's a loop because the game keeps doing a series of actions over and over again until the user quits. If a game runs at 60 FPS (frames per second), this means that the game loop completes 60 iterations every second.- Author:
- kong
-
-
Constructor Summary
Constructors Constructor Description AbstractHeartBeat()
Create a new instance with default FPS value, see 60AbstractHeartBeat(int viewWidth, int viewHeight)
Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected int
_getFPS()
Retrieves the FPSprotected abstract void
_onAction1()
Customize the button 1 actionprotected abstract void
_onAction2()
Customize the button 2 actionprotected abstract void
_onAction3()
Customize the button 3 actionprotected abstract void
_onCreate()
It is called when start a game loopprotected abstract void
_onDispose()
It is called when the game loop is stopped or destroyedprotected abstract void
_onMessage(TObject message)
It is called when the heart-beat receives a message from outsideprotected abstract void
_onPause()
It is called when you call_pause(boolean)
with true parameterprotected abstract void
_onRender(Paint paint)
It is called every frame after_onUpdate(float)
protected abstract void
_onResume()
It is called when you call_pause(boolean)
with false parameterprotected abstract void
_onUpdate(float deltaTime)
It is called every frame in a game loopprotected void
_pause(boolean pause)
Pause game loopvoid
actionPerformed(java.awt.event.ActionEvent e)
java.lang.Void
call()
void
debug(java.lang.String title)
Display a window for debuggingvoid
setMessageListener(java.util.TreeSet<com.tenio.engine.heartbeat.HMessage> listener)
Set the listener for the heart-beat.void
setTextAction1(java.lang.String text, java.awt.Color color)
void
setTextAction2(java.lang.String text, java.awt.Color color)
void
setTextAction3(java.lang.String text, java.awt.Color color)
-
-
-
Constructor Detail
-
AbstractHeartBeat
public AbstractHeartBeat()
Create a new instance with default FPS value, see 60
-
AbstractHeartBeat
public AbstractHeartBeat(int viewWidth, int viewHeight)
Create a new instance- Parameters:
viewWidth
- the view width in pixelviewHeight
- the view height in pixel
-
-
Method Detail
-
setMessageListener
public void setMessageListener(java.util.TreeSet<com.tenio.engine.heartbeat.HMessage> listener)
Set the listener for the heart-beat. It's used to communicate with outside. This method must be called beforecall()
- Parameters:
listener
- the messages' listener
-
_pause
protected void _pause(boolean pause)
Pause game loop- Parameters:
pause
- set true if you want to pause the current game loop
-
_getFPS
protected int _getFPS()
Retrieves the FPS- Returns:
- the FPS
-
debug
public void debug(java.lang.String title)
Display a window for debugging- Parameters:
title
- the title of debug window
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
-
setTextAction1
public void setTextAction1(java.lang.String text, java.awt.Color color)
-
setTextAction2
public void setTextAction2(java.lang.String text, java.awt.Color color)
-
setTextAction3
public void setTextAction3(java.lang.String text, java.awt.Color color)
-
call
public java.lang.Void call() throws java.lang.Exception
- Specified by:
call
in interfacejava.util.concurrent.Callable<java.lang.Void>
- Throws:
java.lang.Exception
-
_onCreate
protected abstract void _onCreate()
It is called when start a game loop
-
_onMessage
protected abstract void _onMessage(TObject message)
It is called when the heart-beat receives a message from outside- Parameters:
message
- the coming message, seeTObject
-
_onUpdate
protected abstract void _onUpdate(float deltaTime)
It is called every frame in a game loop- Parameters:
deltaTime
- the time between two frames
-
_onRender
protected abstract void _onRender(Paint paint)
It is called every frame after_onUpdate(float)
- Parameters:
paint
- the painting object
-
_onPause
protected abstract void _onPause()
It is called when you call_pause(boolean)
with true parameter
-
_onResume
protected abstract void _onResume()
It is called when you call_pause(boolean)
with false parameter
-
_onDispose
protected abstract void _onDispose()
It is called when the game loop is stopped or destroyed
-
_onAction1
protected abstract void _onAction1()
Customize the button 1 action
-
_onAction2
protected abstract void _onAction2()
Customize the button 2 action
-
_onAction3
protected abstract void _onAction3()
Customize the button 3 action
-
-