Skip to content

Using CrynnObjects

Weston McNamara edited this page Jun 7, 2021 · 3 revisions

If you're new to Crynn, it can be pretty easy to forget how to use the CrynnObject class. It's a super important class, but can be a bit confusing. Lets learn how to use it.

Basic Class Usage

CrynnObject is intended to be inherited from. Objects in Crynn are inheritance based, so if you need to create an object in your game, make a class for it, and have it inherit from the CrynnObject class.

Correct Usage:

class Example : CrynnObject
{
private:
    void Update(float deltaTime) override; //called every frame
    void Start() override; //called when the engine is initialized
};

When an instance of this class is created, the Update and Start function will automatically subscribed to the Crynn event system, and will be handled automatically.

Incorrect Usage

int main() 
{
    CrynnObject object;
}

CrynnObject inherits from EventListener, which provides a set of virtual functions you can override to interact with the Crynn event system. These are as follows.

Function Signature Usage
void Update(float deltaTime) Called every frame. deltaTime is the time in
seconds the previous frame took to render.
void Start() Called when the engine is initialized. Check the note for Unity users below for more information.
void Render() Called before the engine renders a frame. Useful for rendering operations
void BeforeUpdate(float deltaTime) Called every frame, before Update(). deltaTime is the time in
seconds the previous frame took to render.
void BeforeClose() Called before the engine terminates.

Note For Unity Users

void Start() is NOT called when the object is created, like in Unity. It is only called when the engine is initialized. If you need to run code to initialize your objects when they're created, do so in the constructor.

Clone this wiki locally