Layers and tiles
The layers are the ones in the room’s Camadas panel. In the code, a layer is always referred to by its name, in quotes.
Instances and layers
Section titled “Instances and layers”| Function | What it does | Example |
|---|---|---|
T* spawn<T>(float atX, float atY, std::string_view layer) |
Creates an instance of T in the layer layer. Returns nullptr (with an error in the Output) if the layer does not exist or is not an Instâncias layer. |
spawn<Bullet>(x, y - 8, "Tiros"); |
T* spawnAtDepth<T>(float atX, float atY, int atDepth) |
Creates an instance outside the layers, at a chosen depth. | spawnAtDepth<Faisca>(x, y, -50); |
void setLayer(std::string_view layer) |
Moves this instance to another Instâncias layer. | setLayer("Frente"); |
const std::string& layerName() |
The name of this instance’s layer ("" if it is outside the layers). |
if (layerName() == "Fundo") ... |
Show, hide and move
Section titled “Show, hide and move”| Function | What it does | Example |
|---|---|---|
void setLayerVisible(std::string_view layer, bool show) |
Shows or hides a layer. | setLayerVisible("Segredo", true); |
bool layerVisible(std::string_view layer) |
true if the layer is visible. |
if (layerVisible("Segredo")) ... |
void setLayerPosition(std::string_view layer, float x, float y) |
Puts the corner of a Fundo (background) layer at (x, y) of the room. |
setLayerPosition("Montanhas", scene().camera.x * 0.5f, 40); |
float layerX(std::string_view layer) and layerY |
The current position of the layer. | float px = layerX("Montanhas"); |
| Function | What it does | Example |
|---|---|---|
int tileAt(std::string_view layer, float atX, float atY) |
The number of the tile at that point of the Tiles layer (the first one in the tileset is 0), or -1 if there is no tile. |
if (tileAt("Chao", x, y + 12) == 7) ... |
bool solidAt(float atX, float atY) |
true if there is something solid at that point: a solid tile or an instance with solid. |
if (solidAt(x + 10, y)) flipX = !flipX; |
- The depth of an instance comes from the layer it is in.
depthcan still be read and changed in the code, butsetLayeris the clearest way to change the drawing order. - Hiding an Instâncias layer only stops drawing them: they keep running and colliding.
- A hidden Tiles layer keeps blocking movement. To make it stop colliding, turn Colide off in the editor.
- Solid tiles are included by themselves in
placeFree,moveAndStop,onGround,hitFloor,hitWallandhitCeiling. See Collision and Movement. - Tiles do not change while the game is running in this version.
The game window
Section titled “The game window”For a video options menu. What is in the project settings is only the initial value.
| Function | What it does | Example |
|---|---|---|
void Window::setFullscreen(bool on) |
Enters full screen or goes back to the window. | Window::setFullscreen(!Window::fullscreen()); |
bool Window::fullscreen() |
true if the game is in full screen. |
if (Window::fullscreen()) ... |
void Window::setScale(WindowScale scale) |
How the image is scaled up: WindowScale::Integer, Fit (keep the aspect ratio) or Stretch. |
Window::setScale(WindowScale::Fit); |
WindowScale Window::scale() |
How the image is being scaled up. | if (Window::scale() == WindowScale::Fit) ... |
void Window::setSize(int width, int height) |
Changes the size of the window, in screen pixels. In full screen it does nothing. | Window::setSize(1280, 720); |
int Window::width() and height() |
The current size of the window. | int w = Window::width(); |
int Window::screenWidth() and screenHeight() |
The size of the monitor. | if (Window::screenWidth() >= 1920) ... |
The resolution of the game does not change with setSize: the image is scaled up to the new size.
See Scenery with tiles and Parallax background.
