Skip to content
Download

Objects and events

An object is a type (Player); an instance is each copy of it in the room. The behavior lives in the events of the object.

objects/Player.lua
function onSpawn(self)
self.vidas = 3
end
function onUpdate(self)
self.hspeed = axis("esquerda", "direita") * 2
end
  • Lua: what belongs to the instance uses self.field and self:method(). Everything else is a free function (spawn, held, goTo).
  • C++: the object is a class derived from brasa::Entity, registered with BRASA_ENTITY. Fields and functions are its members. See C++ in Brasa.
  • The reference tables show the name and the arguments; the exact form in each language is in the example.
Event When it runs
onSpawn Once, when the instance is created, with its position and Inspector values already set.
onUpdate Every step (60 per second), after the timers.
onPausedUpdate Every step while the game is paused, instead of onUpdate.
onRender When the instance is drawn, in the world. The default draws the sprite (drawSelf).
onRenderGui When drawing on top of everything, in screen coordinates, with no camera.
onDestroy When the instance is removed, at the end of the step.
onAnimationEnd When the sprite animation completes a loop.

The order inside a step is in Step order.

Property What it is
x, y Position in the world (the sprite origin). y grows downward.
sprite Sprite name. Empty = no drawing and no collision.
frame Current animation frame, starting at 0. Returns to 0 when the sprite changes.
animSpeed Animation speed multiplier (1 = the sprite fps; 0 = stopped). With no fps on the sprite, it is frames per step.
scaleX, scaleY Drawing scale. Negative mirrors.
angle Drawing rotation in degrees, clockwise. Does not affect collision.
flipX Mirrors the drawing and the collision box horizontally.
depth Drawing order: higher is further back. Comes from the instance layer.
visible false = it is not drawn.
solid Blocks moveAndStop and placeFree of other instances.
mask Name of a sprite that provides the collision box, instead of the current sprite.
persistent true = the instance survives a room change.
objectName Name of the object the instance came from. Read-only.
layerName Name of the instance layer. Read-only.

Speed, gravity and friction are in Movement. In C++, objectName() and layerName() are functions.

Function What it does
destroy() Marks the instance to be removed at the end of the step.
exists() Lua: true while the instance has not been removed.
isDestroyed() C++: true if destroy() has already been called.
function onUpdate(self)
if self.y > roomHeight() then self:destroy() end
end