Skip to content

Basic engine usage (objects & calls)

Michele edited this page Oct 26, 2019 · 4 revisions

Preface

Most of the "basic engine usage" Wiki is based on the SimpleGame code, so there will be examples referring to that code.

This page assumes that you have already read "basic engine initialization".

SGameObject utils

The main abstract GameObject is the class SGameObject. Every SGameObject can use three events:

  • game_start() it's executed before the engine start to run the GameLoop. (Executed on every SGameObject registered)
  • game_update(float time) it's executed every frame, allowing to do game updates about position or everything you need. (Executed on every SGameObject registered with should_update == true). Remember that doing heavy stuff on the update method can reduce the framerate.
  • on_gui() it's used to draw gui element with imgui instructions. See SimpleGame MainMenu for examples.

But there are other events you can use as you prefer, there are: spawn(), respawn(), die() and kill(). By default these methods do nothing, but you can decide to use them, for example: SimpleGame player class (Ball) use respawn() to respawn the player on the checkpoint if the player fell the platform.

Using the engine

Now that you have initialize the engine, it's time to use it.

As described in the previous article, there are few things to keep in mind, let's see a list:

  1. A GameObjects doesn't execute game_start(), game_update(...) and on_gui() if it hasn't been registered in the LogicManager.

  2. Every Component created from the ComponentsManager, must be deleted from him. This because it keep a lot of informations about the available components and all the connected stuff, so you can't just delete a Component. For example, if you load a mesh with create_new_mesh_component(...) you must delete it calling destroy_mesh_component(...). This is very important and valid for every kind of component. Deleting a component with a delete call will probably lead to errors immediately or in the future.

I want to know more

To know more, you can give a look at "basic components".

Clone this wiki locally