- 1. Getting Started with OdyC
- 2. Naming Your Game
- 3. The Hero
- 4. How to Draw?
- 5. The Map
- 6. Dialogues
- 7. Sound in the Game
- 8. Advanced Template Parameters
- 9. Camera Control
- 10. Integrating Events
- 11. Event Target Manipulation
- 12. Dynamic Hero Modification
- 13. Modifying a Cell
- 14. Global Model Modification
- 15. Orchestration of Dialogues, Sounds, and Endings
- 16. Dynamically Loading Maps
In the previous section, target.remove()
was introduced as a means to remove an object from the game. However, the target object (target
) in the functions onCollide
, onEnter
, or onLeave
offers much more potential.
Modifiable Properties
When an event is triggered, the target object is passed as a parameter to the associated function. This allows you to modify or even delete the object in question. Here are the properties you can read and modify:
- Sprite (
sprite
): Changes the appearance of the object. - Dialogue (
dialog
): Modifies the text displayed during interaction. - Solidity (
solid
): Determines whether the object is passable. - Visibility (
visible
): Controls the display of the object. - Sound (
sound
): Changes the sound played during interaction. - End (
end
): Defines an end message or concluding action.
Read-Only Properties
Some properties are read-only:
- Symbol (
symbol
): The character representing the object in themap
. - Position (
position
): The coordinates of the object in the game.
Object Removal
The object can be removed with the remove()
method, which takes it out of the game:
Practical Example
Imagine wanting to toggle an object X
’s visibility each time the player collides with it. Use the visible
property in an onCollide
function:
Loading editor...
createGame({ templates: { X: { sprite: 3, } }, map: ` ........ .X...... ........ ........ ........ ........ ........ ........ ` })