[HELP] [NUI] mousedown / mouseup event listeners not working

Hi. I am working on a new resource. I wanted to make my first NUI script. However, it is not completely working. I am attempting to make a scratch card, howeverrr it is not changing/scrarching when moving mouse over. It works in a default html browser, just not in-game.

This is the script
https://hastebin.com/duloxadidi.js

The following part is working:

var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d');
var rect = canvas.getBoundingClientRect();

canvas.width = 248;
canvas.height = 226;
ctx.fillStyle = "#CDAC5C";
ctx.fillRect(0, 0, canvas.width, canvas.height);

Shouldn’t the event listener names be:

onmousedown
onmousemove
onmouseup

Instead of:
mousedown
mousemove
mouseup

Nah. After some debugging it turns out it does not like these:

ctx.globalCompositeOperation = 'destination-out';
ctx.fillRect(e.clientX - rect.left - 25, e.clientY - rect.top - 25, 50, 50);

No clue why but I just switched over to a different scratching mechanic and managed to get it working. Thanks though!

This sounds really fun btw.
Would love to see the end result!

1 Like

Well, I just releasted it! Feel free to check it out: