Planet
navi homeaboutscreenshotsdownloaddevelopmentforum

HowTo?: Tickable

TracNav(TracNav/TOC_Development)?

A tick is one frame or one iteration of the main-loop. Classes can be called every tick. This is achieved by inheriting from 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 8 years ago Last modified on Oct 10, 2008, 3:36:39 AM