Objects
Objects are what you place by hand on an object layer:
- Sprites of the project (
.spr): the player, the enemies, the coins. - Images: in the game they are one-frame sprites.
- Shapes: rectangles, ellipses and lines that the game draws.
- Zones: rectangles that are not seen and that the rules watch.
- Routes: paths for the Follow route behaviour.
Each object is set up in the INSTANCE section of the Object tab. What they do in the game without writing code is told in Behaviours and Rules and states.
Placing objects
Sprites and images are placed from the ASSETS palette, below the canvas, with an object layer active:
- Click a sprite or an image in the palette.
- Choose Place (
2) and click on the canvas. Before the click, a ghost shows where it will land.
You can also drag it from the palette onto the canvas, or double-click it: then it goes to the centre of what you are looking at. What you place is left chosen.
With View › Snap to the grid on, the object snaps to the cell: its box lines up with the Room › Snap (px) grid, and its pivot falls inside the cell you clicked. Dragging an object does the same, and Alt drops the snapping while you drag.
With Place, a click on an object of the same resource chooses it, instead of putting another one on top. To stack two identical ones, drag the second one from the palette.
What you place inherits from the last object of the same resource its tag, its body, its physics (except Velocity and Spin / Ang. vel.), Keep in room and its behaviours. The name, the place, the states and the code belong to each one. The name comes from the resource: Hero.spr gives hero, and the next ones hero2, hero3…
To move what is chosen, drag it with Select (1) or use the arrow keys: one grid step, or one pixel with Shift. With Ctrl held while you drag, you move a copy. Choosing several, copying, aligning and the rest of the canvas are in Scene editor; the drawing order, in Layers.
The inspector (INSTANCE)
With an object chosen, INSTANCE shows its fields. At the top it says what it is and from which resource: sprite - Hero.spr, image - Rock.bmp, shape, marker (a zone) or route - 4 nodes, 380 px.
- Text boxes apply when you press
Enteror leave them. What is not a number leaves the value as it was, and what goes past its limits is clipped: a mass of 0 goes back to 1, a friction of 3 stays at 1. Decimals can use a point or a comma. - With several objects chosen, the panel shows the main one: the last one you chose. Tag, Body, Group, Passes and Use sprite collider apply to all of them, and Position moves them all by the same amount. The rest only goes to the main one. Name is greyed out, because it must be unique.
- What a kind of object does not have is greyed out or not shown. A shape, a zone or a route has no body, rotation or flip rows.
Name, tag and position
- Name: the name the game finds it by (
room.named["hero"]) and the one other objects and the rules point to. It must be unique in the room. If you change it, whatever named it follows the new name. An object with no name is not inroom.named, and the tree shows it as(unnamed). - Tag: its kind:
enemy,coin,bullet. The rules work with tags. Capitals count:Enemyandenemyare two different tags. If you change a tag and nobody carries the old one any more, the rules that named it move to the new one. - Position: in pixels of the room.
- On a sprite it is its pivot, the centre unless its
.sprsays otherwise: the same valuessprite.xandsprite.ywill have in the game. The box is then called Position (pivot). - On everything else it is the top-left corner: Position (corner). An image goes into the game as a sprite with its pivot in the centre, so there its
xis that corner plus half its width.
- On a sprite it is its pivot, the centre unless its
- Size (px): only on shapes and zones. Sprites and images come out at their own size, because the VM does not scale them.
- Angle / Frame: the first box is the rotation, in degrees, from 0 to 360 and clockwise. Only on sprites and images. On the canvas you turn it with its handle; with
Shift, 15 degrees at a time.
Flip and starting frame
- Flip X and Flip Y, or the
HandVkeys, flip the sprite or the image horizontally and vertically. - The second box of Angle / Frame is the frame of the sheet the sprite starts on. At 0, it animates as its
.sprsays. With another one, it stays still on that frame: the room sets itsframeRateto 0. To animate it from there, use the Animation behaviour.
The body
Body says how the physics treats the object. It is the sprite's bodyType (Sprite module).
| Body | In the game |
|---|---|
| Visual | No body: it neither falls nor collides with anything. |
| Dynamic | Falls with the room's gravity and collides with the other bodies. <Room>Resolve pushes it out of the solid cells of the collision map. |
| Static | Never moves, and the other bodies collide with it: a floor or a wall made of sprites. |
| Kinematic | Does not fall. It moves with its velocity, the one in Velocity or the one a behaviour or your code gives it, and dynamic bodies collide with it. The collision map does not stop it. |
- Bodies need the room's physics (Room › PHYSICS › Enabled). Without it, nothing falls and velocity moves nothing.
- In a room with physics, a behaviour that moves things by velocity only moves Dynamic or Kinematic bodies. With Visual or Static the object stays still, and the problems panel warns you (Behaviours).
- The rules that check whether two objects touch work with any body: they check whether they overlap.
The body's physics
Below Body come the numbers of the body. Each one is enabled only for the bodies that use it: with another body it is kept, but it does not reach the game.
| Field | Bodies | What it does |
|---|---|---|
| Fixed rotation | Dynamic | Collisions never tilt it (sprite.rotates set to false). Off, it can tip over and roll. |
| Continuous collision | Dynamic | Sweeps each whole step, so a fast body does not go through another one (sprite.bullet). The contact rules do not see its hits: the problems panel warns you. |
| Mass | Dynamic | How heavy it is in a collision (sprite.mass). The default is 1. |
| Fric. / Bounce | Dynamic, Static, Kinematic | Friction and bounce, from 0 to 1 (sprite.friction and sprite.elasticity). A contact uses the average of the two bodies. The defaults are 0 (it slides for ever) and 0.5 (it bounces back half of its speed). |
| Gravity scale | Dynamic | How much of the room's gravity it gets (sprite.gravityScale): 1 all of it, 0 none (it floats) and, negative, upwards. |
| Damp. / Ang. | Dynamic | Slow it down on its own, moving and turning (sprite.damping and sprite.angularDamping). At 0 they do not slow it; at 2, it stops in about a second. |
| Group / Passes | Dynamic, Static, Kinematic | Its collision group, from 1 to 16, and the groups it passes through, such as 2,5 or all. An empty Passes collides with all. |
| Velocity (px/s) | Dynamic, Kinematic | The velocity it starts with, in pixels per second (sprite.vx and sprite.vy). A Kinematic body keeps it; a Dynamic one starts with it. |
| Spin / Ang. vel. | Spin: all. Ang. vel.: Dynamic, Kinematic | In degrees per second. Spin (sprite.spin) turns the picture. Ang. vel. (sprite.angularVel) turns the body: a Kinematic body keeps it and a Dynamic one starts with it. ±720 at most. |
| Keep in room | All | <Room>Resolve does not let the sprite leave the room on any of its four sides. |
- Gravity scale and Velocity do nothing with Linear motion, Patrol, Follow / flee or Top-down control: those behaviours set the velocity themselves.
- Group / Passes only filters the collisions between bodies. Two bodies collide if each one accepts the other's group. The rules and the collision map ignore it. In code they go in bits (
sprite.categoryandsprite.collideWith): group 1 is 1; group 2, 2; group 3, 4, and so on.
The Sprite module explains all of this.
The collider
The collider is the box, or the circle, the object collides with. It belongs to the sprite: you draw it in the sprite editor, and the room uses that one. It only counts for objects with a body, or with hits().
The Collider row says which one it has, in pixels of the frame (Rect 2, 2 12 x 14 or Circle 12, 12 r 10), and below it, where it comes from:
- From the sprite. Change it in the Sprite editor: the one you drew on the sprite.
- Whole frame: the sprite does not set one: the sprite has no collider, and the box is the whole frame.
- The whole image. Make it a sprite to fit it: an image collides with the whole image. To fit it, make a sprite with it.
Rooms made with an earlier version of the editor may have objects with their own box: the row says Own rect …, and the game uses it. Use sprite collider drops it, and the object goes back to its sprite's.
View › Colliders draws the colliders on the canvas.
Shapes and zones
Shape (3) and Zone (4) draw a rectangle on the active object layer: drag from one corner to the other. A click without dragging makes one the size of a tile (Room › Tile size). With View › Snap to the grid, the corners go to the grid. They are born with the names shape, zone, zone2…
They stretch with their handles, and Size (px) gives them an exact size. They do not rotate, do not flip and have no body: they collide with nothing.
Shapes
- Shape chooses the shape: Rect, Ellipse (the ellipse that fits in the box; with a square box, a circle) or Line (from the top-left corner to the bottom-right one).
- The colour square changes its colour, and Filled fills it.
- In the game,
<Room>Drawdraws them withDraw.rect,Draw.ellipseandDraw.line, in the place of their layer in the stack (drawing order). A shape hidden with its eye is not drawn.
Zones
A zone is not seen in the game. It marks a place in the room, such as the exit or a pit, for these to watch:
- the When it enters a zone rule (Rules and states);
- the Inside zone field of the Spawner behaviour and of the Create from a template action: the copies appear inside the zone.
Shapes also work in those fields. The panel calls zones marker.
Show in game makes the game draw the zone as a rectangle of its colour, so the player sees where the exit is. With it on, the colour square and Filled are enabled.
Shapes and zones in code
The room leaves its shapes and zones in a table, <ROOM>_ZONES, with a row for each one: [name, tag, kind, shape, x, y, w, h, color, filled]. <Room>Zone(name) finds one by its name and returns its row, or nil. Both are only written if your code names them: build after naming them and they appear.
// The "exit" zone of the Level1 room, from the game code
var exitZone = Level1Zone("exit")
if (exitZone != nil) then
// [name, tag, kind, shape, x, y, w, h, color, filled]
println(exitZone[4]) // its x
end
Routes
Path (6) draws a route: a broken line, node by node, that the Follow route behaviour walks (Behaviours).
- Each click adds a node. A click on a segment inserts one in between, and dragging moves a node.
Delremoves the node under the mouse, or the last one.Esc,Enteror a double-click end the route.- With Select, the nodes of the chosen route move the same way. Right-click gives you Delete this route node and Reverse the route, and the
HandVkeys mirror it. - They are born with the names
route,route2…
A route is data: it is not seen in the game, and it has no body or behaviours. Follow route finds it by its tag, so give it one in Tag. A route hidden with its eye does not count. The panel says how many nodes it has and how long it is, so you can work out how long it takes at its speed.
If there is no route with that tag, the zones and shapes that carry it work as a route: they are walked through their centres, in the order of their names (zone2 before zone10).
Properties
PROPERTIES keeps your own data in the object: pairs of name and value, such as lives = 3 or key = red. The editor does not use them: they are for your code.
- Add asks for the name of the property and creates it with the value
0. The value is changed in the Value column. - Remove removes the chosen property.
- The name cannot be changed in the grid: remove the property and create it again.
Each value reaches the game with its type:
| If the value is… | It arrives as |
|---|---|
true or false | a boolean |
nil | nil |
a number, with a decimal point: 3, 0.5 | a number |
anything else: red, 0,5 | a string |
The properties reach the game in three places:
- The object's code, as
props(see "The code of each object"). - The
spawn(e)function you can pass to<Room>Load, ase.props. - The room's table,
<ROOM>_ENTITIES, in thepropsfield of each object's row. The row of a named object is given by the<ROOM>_I_<NAME>constant, which is written if your code names it.
An object with no properties has props set to nil.
// The "key" property of the "door" object of the Level1 room
var row = LEVEL1_ENTITIES[LEVEL1_I_DOOR]
if (row.props != nil) then
if (row.props.contains("key")) then
println(row.props["key"]) // red
end
end
Templates
A template is an object kept with no position. The game makes copies of it while it plays:
- the Spawner behaviour, every so often (Behaviours);
- the Create from a template action of a rule (Rules and states).
They are handled in the TEMPLATES block, at the end of INSTANCE:
- Make template (From object) makes a template out of the chosen object. Only a sprite can be a template. It takes the object's name; if it has none, its tag, and if not that either,
Template. - Template chooses one of the room's templates, and Remove deletes it.
- Name renames it. The spawners and actions that used it follow it.
- Below, it says what it carries, such as
sprite, 2 component(s), tag "coin", with code.
Templates also appear in the tree, in the TEMPLATES group. They live inside the room: to use one in another room, copy the object there and make the template again.
Each copy carries everything in the template: its sprite, its body and physics, its tag, its behaviours, its states and its code. It appears wherever whoever creates it says, and with no name: it is not in room.named. Its properties only reach its code, as props: if the template has properties but no code, the problems panel warns you.
A template is a snapshot of the object at that moment: if you change the object later, the template does not change. To bring it up to date, delete it with Remove and make it again from the object. If it gets the same name, the spawners and actions that used it find it again.
The code of each object
CODE › Edit code... opens the Object code window, with the JARU code of the chosen object. Only sprites and images can have it, and not those on a decor layer.
What you write there is the body of a function: lines of JARU that can use three names.
spr: the object's sprite.room: the room, with the other objects inroom.named.props: its PROPERTIES, ornilif it has none.
It runs once, when the room loads: when all its objects have been created and their behaviours attached, and before the object enters its first state. Also in every copy of a template made from the object. It runs before the room's creation code (The room and the game). Objects with the same code share a single function in the .gen.aru.
// The same code on three Kinematic enemies, in a room with physics.
// Each one has its own "speed" in PROPERTIES: 40, 60, 80
var speed = 40
if (props != nil) then
if (props.contains("speed")) then
speed = props["speed"]
end
end
// Towards the player, if it is in the room
if (room.named.contains("hero")) then
var hero = room.named["hero"]
if (hero.x < spr.x) then
speed = 0 - speed
spr.flipX = true
end
end
spr.vx = speed
The window is edited like the IDE's code editor: colours, autocompletion, the signature of what you call, Ctrl + click to go to a definition and underlined errors. The line at the bottom gives the error where the cursor is. room. offers the room's fields as they were the last time it was generated: if it has never been generated, it offers nothing.
The window follows the object you choose. What you write goes into the room when you leave the window or close it with Close, and it goes into undo. Below Edit code..., the panel says how many lines of code the object has.
active = false means destroyedIn a room with behaviours, states, rules, templates, variables or code, <Room>Update takes out of the scene, at the end of every frame, the sprites whose active is false. Setting it back to true does not bring them back. If an object has to show up again, make a template of it and create a copy when you need it.
Known issues
- Position takes no negative values. An object dragged to the left of or above the room shows 0 in Position, and if you change the other axis in its box, the object jumps to 0. Move it with the mouse or the arrow keys.
- PROPERTIES does not go into undo properly. Changing a value in the grid leaves no step:
Ctrl+Zundoes whatever came before. And Add with the name of a property that already exists sets it to0without warning. To change a value, edit it in the Value column. - Body does not change on an image. On a placed image, Body goes back to Visual when you choose another body, so an image cannot be a platform. Make a sprite with the image and place the sprite.
- Double quotes arrive with a backslash. A
"in an object's name, in a property or in a text reaches the game with a backslash in front:Boss "bad"arrives asBoss \"bad\". Do not use double quotes there. - Templates can only be handled with an object chosen. With nothing chosen, the TEMPLATES block is greyed out, and its rows in the tree do nothing. To see, rename or delete a template, choose any object first.
- The names of the copies. When you duplicate or paste
enemy2, the copy is calledenemy22, notenemy3. If you number your objects, rename the copy. - The label for several chosen objects falls short. With several objects chosen, the panel says
tag, body, group go to all, but Position and Use sprite collider also apply to all of them.