Layers

In the game world, objects are stored in layers, similarly to how layers work in image editors such as Photoshop. This allows the user to stack objects on top of each other in the same tile. The player exists in a layer just like all other objects (to modify the player's layer attribute, see Player).

## Collision

**Important distinction:**

For objects that are on the **same layer** as the player:

* The object will be **impassible** (player cannot pass through it) unless collision is disabled for that layer.
* To activate the object's collision function, the player must be standing **next to it** and collision must be enabled for that layer.

For objects that are on **a different layer** from the player.

* The object will always be **passible** (player can pass through it), regardless of whether collision is enabled.
* To activate the object's collision function, the player must be standing **over** it and collision must be enabled for that layer.

## How to...

### Change which layer the cursor is in

1. Click on the layer button at the top right corner of the screen until it shows the layer desired. This will allow you to paint and erase objects in the correct layer.

### With code...

#### Add a new layer

1. In the >> command window, select Layer commands > Add new layer
2. Replace these placeholders:
	* `LAYER_NAME :` String. Whatever you wish to name this layer; can be anything. Do not remove the 'apostrophes'
	* `LAYER_INDEX :` Integer. The index (position in line) you wish to give this layer in the array of layers. (See Layer Index below for detail)
	* `VISIBLE_TRUE_FALSE :` Bool. When set to false, layer becomes invisible.
	* `COLLISION_TRUE_FALSE :` Bool. When set to false, player will not collide with objects in that layer. See the collisionEnabled attribute below for detail.
3. Press "execute". You will see your new layer when pushing the layer button at the top right corner of the screen.

#### Delete a layer

(Warning: This deletes all objects currently in that layer)

1. In the >> command window, select Layer commands > Delete layer
2. Replace this placeholder:
	* `LAYER_NAME :` String. The name of the layer you wish to delete. Do not remove the 'apostrophes'
3. Press "execute". You will no longer see this layer when pushing the layer button at the top right corner of the screen.

#### Change layer visibility

1. In the >> command window, select Layer commands > Modify Layer > Change layer visibility
2. Replace these placeholders:
	* `LAYER_NAME :` String. The name of the layer whose visibility you wish to change. Do not remove the 'apostrophes'.
	* `TRUE_OR_FALSE :` Bool. When set to true, layer will be visible. When set to false, layer will be invisible. This does not affect collision.
3. Press "execute".
4. Press "space" to refresh the screen. You will see that any objects in that layer are now visible/invisible.

#### Change whether layer has collision

1. In the >> command window, select Layer commands > Modify Layer > Change whether layer has collision
2. Replace these placeholders:
	* `LAYER_NAME :` String. The name of the layer whose collision you wish to change. Do not remove the 'apostrophes'.
	* `TRUE_OR_FALSE :` Bool. When set to true, layer will have collision. When set to false, layer will not have collision. This does not affect visibility.
3. Press "execute".

#### Change a layer's position

(Changes the order in which layers are rendered; like dragging layers up and down in an image editor such as Photoshop)

1. In the >> command window, select Layer commands > Modify Layer > Change layer position
2. Replace these placeholders:
	* `LAYER_NAME :` String. The name of the layer whose index (position in the list) you wish to change. Do not remove the 'apostrophes'.
	* `NEW_LAYER_INDEX :` Integer. The index (position in the list) you wish to change this layer to. See Layer Index below for more detail.
3. Press "execute".

## Layer Index

Many programming languages (including javascript) have an object type called an array. An array is a list of items. Arrays have a zero-based index. That means that the first item on the array has an index of 0, the second item has an index of 1, the third item has an index of 2, and so on.

In AsciiMason, layers are stored in an array. The first layer (the one on the bottom) has an index of 0. The second layer (second from the bottom) has an index of 1, and so on. The index of the layer at the top is equal to the number of layers minus 1.

## Attributes

Notice that a layer does not store its own index as an attribute.

`{`

`"name": 'LAYER_NAME'`

`"visible": TRUE_OR_FALSE,`

`"collisionEnabled": TRUE_OR_FALSE,`

`"chunks": []`

`}`

### name

String. The name of the layer

`Ex. "Layer 3"`

### visible

Bool. When set to false, layer becomes invisible. This does not affect collision.

`Ex. true or false`

### collisionEnabled

Bool. When set to false, player will not collide with objects in that layer, even if they are on the same layer as the player. This will also disable the collisionFunction and actionButtonFunction of any objects in that layer.

`Ex. true or false`

### chunks

Array. A list of chunkColumns in this layer. This should not be modified. For more detail, see Structure of the Game World.

`Ex. [ (chunkColumn 1), (chunkColumn2), ...]`