Nyra Studios
Manual under construction. Some parts are incomplete or may change.

The level

Nyra 0.5.4.28

The level field of the welcome describes the map. It is there in every movement mode. Your client uses it to draw the world and to know where the walls are: the server makes them count in every mode, each one in its own way.

The shape of the level

json
{
  "name": "Livello 1",
  "worldSize": { "width": 800, "height": 600 },
  "tilesets": [ { "id": "ts-1", "name": "terreno", "image": "terreno.png", "tileWidth": 32, "tileHeight": 32, "spacing": 0, "margin": 0 } ],
  "spriteAssets": [ { "id": "spa-1", "name": "torcia", "image": "torcia.png", "originX": 0.5, "originY": 1, "imgW": 32, "imgH": 64 } ],
  "layers": [
    {
      "id": "layer-1",
      "name": "Terreno",
      "cellSize": 32,
      "tilemaps": [
        {
          "id": "tm-1",
          "name": "base",
          "tilesetId": "ts-1",
          "cellSize": 32,
          "cells": [
            { "col": 0, "row": 0, "tileIndex": 3 }
          ]
        }
      ],
      "shapes": [ { "id": "floor", "x": 0, "y": 400, "width": 800, "height": 40, "label": "solid", "labelId": "builtin:solid", "name": "", "properties": {}, "collision": "solid" } ],
      "points": [ { "id": "sp", "x": 100, "y": 400, "label": "spawn", "labelId": "builtin:spawn", "name": "", "properties": {} } ],
      "sprites": [],
      "tileColliders": []
    }
  ]
}

These are the pieces:

  • name: the name of the map, only to show it. It can be an empty string.
  • worldSize: the size of the world in pixels. It can be null: in that case your client decides by itself.
  • tilesets: the images of the tiles, with the size of every tile.
  • spriteAssets: the images of the sprites. Each one has id, name and image; the anchor point (originX, originY) and the sizes (imgW, imgH) are there when whoever drew the map set them.
  • layers: the layers, one on top of the other. Every layer has five lists: tilemaps, shapes, points, sprites and tileColliders.

Drawing order: layers[0] is the layer in front of all the others, the last one is the furthest back. Draw from the last to the first and, inside each layer, from the bottom up: tilemap cells, sprites, shapes, points. Example: if the first item of layers is “Top” and the second is “Bottom”, everything in “Top” covers “Bottom”. The server sends the array already in this order: you do not need to reverse it.

Inside a layer

  • tilemaps: cells drawn with a tileset. Every cell has col, row and tileIndex, and can have a label with the identifier of the label (for example builtin:solid).
  • shapes: rectangles. They have x, y, width, height, name, properties, the label and collision.
  • points: points, for example where the characters appear. Like the shapes, but without sizes and without collision: a point never blocks.
  • sprites: images put on the map. Each one has id, name, sprite (which image it uses), x, y, rotation, scale, properties, the label, collision and showCollision. Sometimes there are also hitboxWidth and hitboxHeight.
  • tileColliders: the boxes that block, already worked out from the labelled cells and from the sprites with a collision area. They have x, y, width, height, the label and collision. The ones that do not block do not appear.

Labels and collisions

Shapes, points, cells and sprites can have a label. Your client reads:

  • labelId: the stable identifier of the label, for example builtin:solid. It never changes.
  • label: the name to show, for example solid.
  • collision: what the object does in a clash, already decided by the server: solid (it blocks), oneway (you go through it from the sides and from below and you rest on top) or none (it does not block).

You do not have to work the rule out again: use collision. An object without a label has label and labelId equal to null, an empty name and empty properties.

Note

Inside the cells of the tilemaps the label field contains the identifier, for example builtin:solid, and not the name to show.

Who uses the walls

The level describes the walls in every mode, but not all modes make them count:

ModeWhat the server does with the walls
TileIt stops the step towards a cell touched, even partly, by a solid wall. oneway and none are gone through.
Platformsolid and oneway block from above and from below. Horizontally only solid blocks.
8 directionssolid and oneway both block. none is gone through.

In tile a step stopped by a wall does not move the character and does not change its facing: whoever sent the step receives move-rejected with the reason blocked (see the Moving by mode page). If the character already starts inside a wall — for example because the map changed after the save — it walks freely until it reaches a free cell, and from there the walls stop it again. Your client can keep using the collision field to draw or for its local prediction.

The images

The level names the images, but it does not contain them. The client downloads them with a normal HTTP request, on the same port as the WebSocket:

  • Tileset: /tilesets/ followed by the name of the file, for example /tilesets/terreno.png.
  • Sprite: /sprites/ followed by the name of the file.

If the file exists, the server answers 200 with the right type, for example image/png for a .png file, and with Cache-Control: no-cache. The answers can be read from any web page: they have Access-Control-Allow-Origin: *. Online the images are asked for with https:// to the same host name, because there is a proxy in front of the server. If the file does not exist, the server answers 404 with a JSON text that explains what is missing, for example with the error field equal to tileset-not-found or sprite-not-found. The server looks only at the name of the file: if you also put a path in it, it takes it away.

An HTTP request different from these receives a 426 error in plain text.

Note

With a ws:// address the images are asked for with http://, to the same host and the same port. With wss:// you usually use https:// to the same host name.