Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

HowTo: Tickable

A tick is one frame or one iteration of the main-loop. Classes can be called every tick. This is achieved by inheriting from doc/Tickable and implementing the virtual void tick(float dt) function. dt is the time in seconds passed since the last tick.

*.h file:

#include "objects/Tickable.h"

class MyClass : public Tickable
{
    public:
        virtual void tick(float dt);

    private:
        Vector3 position_;
};

*.cc file:

void MyClass::tick(float dt)
{
    // let the object move with 100 units per second in positive x direction:
    Vector3 velocity(100, 0, 0);
    this->position_ += velocity * dt;

    // call tick(dt) of the parent class:
    SUPER(MyClass, tick, dt);
}

(See this for more information about the SUPER macro.)

Last modified 7 years ago Last modified on Apr 12, 2017, 11:49:34 PM