1. Events

1.1. What is Event-Driven Programming?

Event-driven programming is a programming paradigm that executes commands when certain events are triggered. Events can be triggered by human input or even from within the program itself.

1.2. Actimator Event Types

Actimator’s visual language uses Event-driven programming. The visual language consist of commands that control everything from how entities and scenes look or move. These commands are executed when certain events are triggered. Here are some of the events:

  • User Input (Keyboard, Mouse/Touch)
  • Entity (Create/Destroy)
  • Physics (Collisions)
  • Graphics (Before/After Render: 60 times per second)
  • Timer (Tick: 20 times per second)
  • Device (Rotation, Resize Screen)
  • Custom (user-defined)

1.3. Actimator’s Game Engine Execution Cycle

Game engine

Actimator’s game engine is the framework that allows you, the developer, to easily create games. The engine consist of a HTML5 canvas renderer, Box2D physics engine, and Actimator’s visual programming language. The engine cycles through iterations 60 time per second.

At the beginning of each iteration is the Execution Step:

  • The Execution Step begins by calculating physics, for example, if an entity is colliding with another or a movement is being performed. During this physics calculation, Contact Events and the Impact Event can be triggered.
  • The Before Render Event is triggered prior to the render.
  • The physics calculation is followed by rendering. During the render, images are drawn on layers. If a layer is set to be updated, it will be cleared and then redrawn.
  • The After Render Event is triggered when the render completes.

Following the Execution Step, non-Step events can be triggered in the remaining time of the iteration. These events include, in no particular order:

  • User Input – If the player happens to click with the mouse, presses a key on the keyboard, or touches the screen of the device at any time during an iteration
  • Tick Events – The Tick Event “ticks” 20 times per second independent of game engine’s cycle. If one of these ticks occurs during an iteration, the Tick Event is triggered
  • Custom Events – As the developer, you can create custom events. If a Run Command is executed in any of these events during the iteration, a custom event corresponding to that Run Command is triggered.

1.4. Description of each event

On Create

This event is triggered once when an entity is created.

On Destroy

The On Destroy event is triggered once in the instant before the entity is destroyed.

On Tick

The Tick Count is increased by one, 20 times per second, from when the game starts. The Tick event is triggered each time the Tick Count is increased.

On Before Render

This event is triggered right before graphics are rendered on the screen(60 time per second).

On After Render

This event is triggered right after graphics are rendered on the screen(60 time per second).

On Start Contact

This event is triggered once the instant that two entities’ collision boundaries overlap each other.

On Finish Contact

This event is triggered once the instant that two entities’ collision boundaries are no longer overlapping each other.

On Key Down

This event is triggered once when any key is pressed. You can use an If Statement to specify which key is being pressed.

On Key Up

This event is triggered once when any key is released. You can use an If Statement to specify which key is being released.

On Mouse Down / Touch Start

This event is triggered once when the mouse clicks on an entity or when the player touches an entity on their device’s screen.

On Mouse Up / Touch Release

This event is triggered once when the mouse click is released on an entity or when the player releases an entity on their device’s screen.

On Scene Mouse Down / Touch Start

This event is triggered once when the mouse clicks anywhere on the scene or when the player touches anywhere on their device’s screen.

On Scene Mouse Up / Touch Release

This event is triggered once when a mouse click is released anywhere on the scene or when the player releases anywhere on their device’s screen.

1.5. Custom Events

Custom Events are useful for simplifying redundant tasks. There may be an entity in your game that you want to jump, play a sound, and change its image when its clicked on or a key is pressed. This could be accomplished by dragging the code into a custom event called “Jump”. You could then use the Run Command to run the “Jump” event when a mouse or keyboard event is triggered. You can also trigger non custom events using the run command.

Run command

In some situations, you may need to run an event from another entity. You use the Run Entity’s Event Command for this. Just type in the Name of the entity and the event that you want it to run.

Run entity

Custom Events are created the same as all other events. After creating a custom event, you can rename it by double-clicking on its name. Type in a desired name and press enter on the keyboard.

Custom event

1.6. Event Command

The event command returns a value that is influenced by an event.

Event command

You can use the drop-down menu to select which value you want:

Tick Count

The Tick Count increases by one, 20 times per second, from when the game starts.

Mouse/Touch X

Returns the X position on the scene of either the mouse or a touch.

Mouse/Touch Y

Returns the Y position on the scene of either the mouse or a touch.

Collided Entity’s Id

Used in one of the On Contact events, this returns the Name of the entity who’s colliding with This Entity.

Collided Actor

Used in one of the On Contact events, this returns the Actor who’s colliding with This Entity.