onClickDown and onClickUp are API functions that allow
assigning mouse callbacks to an object or UI element in the scene.
onClickDown(target, callback);
onClickUp(target, callback);
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.
An enemy that reacts to mouse clicks:
onClickUp("Enemy1", obj => {
obj.hp -= 10;
console.log(obj.name + " takes damage on click");
});
onClickDown is ideal for immediate visual feedback.onClickUp is the most common event for confirming button actions.