| | 1 | = HowTo: Tickable = |
| | 2 | |
| | 3 | A tick is one frame or one iteration of the main-loop. Classes can be called every tick. This is achieved by inheriting from [wiki:Tickable] and implementing the {{{virtual void tick(float dt)}}} function. ''dt'' is the time '''in seconds''' passed since the last tick. |
| | 4 | |
| | 5 | *.h file: |
| | 6 | {{{ |
| | 7 | #include "objects/Tickable.h" |
| | 8 | |
| | 9 | class MyClass : public Tickable |
| | 10 | { |
| | 11 | public: |
| | 12 | virtual void tick(float dt); |
| | 13 | |
| | 14 | private: |
| | 15 | Vector3 position_; |
| | 16 | }; |
| | 17 | }}} |
| | 18 | |
| | 19 | *.cc file: |
| | 20 | {{{ |
| | 21 | void MyClass::tick(float dt) |
| | 22 | { |
| | 23 | // let the object move with 100 units per second in positive x direction: |
| | 24 | Vector3 velocity(100, 0, 0); |
| | 25 | this->position_ += velocity * dt; |
| | 26 | |
| | 27 | // call tick(dt) of the parent class: |
| | 28 | SUPER(MyClass, tick, dt); |
| | 29 | } |
| | 30 | }}} |
| | 31 | |
| | 32 | (See [wiki:howto/Super this] for more information about the SUPER macro.) |