Objects without code
You want a floor, a wall or a spike: things that just sit still in the level. They don’t need code.
Create
Section titled “Create”In Recursos (Resources), right-click a folder and choose Novo objeto (sem código)… (new object, without code). The object is created with the data only: sprite, Sólido (solid), mask, physics and everything else in the Inspector.
Drag it into the room like any other object.
React to it in the code
Section titled “React to it in the code”An object without code has no class, so you can’t write onCollide<Espinho>. Use the object’s name in quotes:
void Player::onSpawn() { onTouchStart("Espinho", [this](Entity&) { restart(); });}The functions that take the name:
| To | Functions |
|---|---|
| Know whether it touches | touching("Espinho"), collidesAt("Espinho", x, y + 1), findAt("Espinho", x, y) |
| React to contact | onCollide("Espinho", ...), onTouchStart("Espinho", ...), onTouchEnd("Espinho", ...) |
| Count and loop | count("Moeda"), any("Moeda"), each("Chao", ...), destroyAll("Moeda") |
They also work for objects that have a class.
Floor and walls
Section titled “Floor and walls”To keep the player from going through an object, just check Sólido on it: moveAndStop and placeFree already respect every solid, with or without code.
When to create the code
Section titled “When to create the code”An object without code has no events and no variables in the code. If it needs to move, count time or keep a value, create it with Novo objeto… (new object).
See also
Section titled “See also”- Collisions.
- Collision: all the functions.
