Class 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 60
      AbstractHeartBeat​(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 FPS
      protected abstract void _onAction1()
      Customize the button 1 action
      protected abstract void _onAction2()
      Customize the button 2 action
      protected abstract void _onAction3()
      Customize the button 3 action
      protected abstract void _onCreate()
      It is called when start a game loop
      protected abstract void _onDispose()
      It is called when the game loop is stopped or destroyed
      protected abstract void _onMessage​(TObject message)
      It is called when the heart-beat receives a message from outside
      protected abstract void _onPause()
      It is called when you call _pause(boolean) with true parameter
      protected 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 parameter
      protected abstract void _onUpdate​(float deltaTime)
      It is called every frame in a game loop
      protected void _pause​(boolean pause)
      Pause game loop
      void actionPerformed​(java.awt.event.ActionEvent e)  
      java.lang.Void call()  
      void debug​(java.lang.String title)
      Display a window for debugging
      void 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 pixel
        viewHeight - 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 before call()
        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 interface java.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 interface java.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, see TObject
      • _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