Skip to content

# Sensor

A sensor is an invisible detector that triggers something when the hero overlaps it.

This type of map entity can be declared in the map data file. It can also be created dynamically with `map:create_sensor()`.

## Overview

Unlike switches, sensors cannot be avoided by a jump. If you want the hero to be detected for sure when he enters somewhere, use a sensor rather than an invisible switch.

When a sensor is activated, the event `sensor:on_activated()` is called. Define that event to implement what happens: closing a door, starting a dialog, etc.

Sensors can have any size, but like all entities, their width and height must be multiples of 8 pixels. The minimum size if 16×16 pixels (the size of the hero).

A sensor is activated only if the bounding box of the hero is entirely on the sensor.

## Methods Inherited from map entity

Sensors are particular map entities. Therefore, they inherit all methods from the type map entity.

See entity to know these methods.

## Methods of the type `sensor`

None.

## Events inherited from map entity

Events are callback methods automatically called by the engine if you define them.

Sensors are particular map entities. Therefore, they inherit all events from the type map entity.

See entity to know these events.

## Events of the type sensor

The following events are specific to sensors.

### `sensor:on_activated(hero)`

Called when the hero overlaps this sensor.

`hero` ()
  The hero that activated the sensor.

The bounding box of the hero (of size 16×16 pixels) must fit entirely the sensor. This means that if the sensor has a size of 16×16, the hero and the sensor must overlap perfectly.

This event is the right place to define the action that you want your sensor to perform.

### `sensor:on_activated_repeat()`

Called continuously while the hero overlaps this sensor.

### `sensor:on_left()`

Called when the hero stops overlapping this sensor.

### `sensor:on_collision_explosion()`

Called when an explosion touches this sensor.

April 1, 2025