πŸ–±οΈ onClickDown & onClickUp

What are they?

onClickDown and onClickUp are API functions that allow assigning mouse callbacks to an object or UI element in the scene.

πŸ“– Syntax

onClickDown(target, callback);
onClickUp(target, callback);

βœ… Basic example

Suppose you have a UI button called StartButton:

onClickDown("StartButton", obj => {
  obj.color = "#888"; // change color on press
});

onClickUp("StartButton", obj => {
  console.log("Button clicked!");
  obj.color = "#0f0"; // change color on release
});

πŸ‘‰ This makes the button change color while pressed and perform the action when released.

βœ… Another example with world objects

An enemy that reacts to mouse clicks:

onClickUp("Enemy1", obj => {
  obj.hp -= 10;
  console.log(obj.name + " takes damage on click");
});

πŸ“Œ Notes

- Both events only trigger if the click happens inside the object's boundaries.
- onClickDown is ideal for immediate visual feedback.
- onClickUp is the most common event for confirming button actions.
- You can assign multiple callbacks to different objects; it does not interfere with the engine’s UI system.