Program Listing for File timer_node.h¶
↰ Return to documentation for file (simple2dengine/nodes/timer_node.h
)
#ifndef _SIMPLE2DENGINE_NODES_TIMER_NODE_H_
#define _SIMPLE2DENGINE_NODES_TIMER_NODE_H_
#include <functional>
#include <string>
#include "simple2dengine/engine.h"
#include "simple2dengine/nodes/node.h"
namespace simple2dengine
{
class TimerNode : public Node
{
public:
TimerNode(const std::string& nodeName, unsigned int time = 0, bool isOneShot = true)
: Node(nodeName), finishTime(time), oneShot(isOneShot){};
void setTime(unsigned int time);
void start();
void pause();
void reset();
bool isPaused() const;
void setOneShot(bool oneShot);
bool isOneShot() const;
void onTimeout(std::function<void()> function);
protected:
virtual void update(int deltaInMs) override;
private:
unsigned int finishTime = 0; // amount of time need to send finish signal
unsigned int elapsedTime = 0; // current elapsed time
bool oneShot = true; // if true - timer will not restart
bool paused = false; // if pause if true - time will not elapse
std::function<void()> timeoutFunc; // signal on timeout
};
} // namespace simple2dengine
#endif // _SIMPLE2DENGINE_NODES_TIMER_NODE_H_