0 Members and 3 Guests are viewing this topic.
function checkmouse(event){ var x = event.clientX - drawingCanvas.offsetLeft; var y = event.clientY - drawingCanvas.offsetTop; context.fillRect(x, y, 5, 5);}
You could try defining both window.onmousedown and and then defining window.onmousemove as well.
function checkmouse(event){ window.onmousedown = mousedown; function mousedown() { var x = event.clientX - drawingCanvas.offsetLeft; var y = event.clientY - drawingCanvas.offsetTop; context.fillRect(x, y, 5, 5); }}
Define some variable to represent the state of the mouse as down or up, then make it "true" when mouseDown is triggered and "false" when mouseUp is triggered.
Yes, but when do I check if it's up or down?
Quote from: ephan on October 03, 2011, 02:59:13 amYes, but when do I check if it's up or down?window.onmousemove
Quote from: Ikkerens on October 02, 2011, 04:03:04 pmYou could try defining both window.onmousedown and and then defining window.onmousemove as well.Code: [Select]function checkmouse(event){ window.onmousedown = mousedown; function mousedown() { var x = event.clientX - drawingCanvas.offsetLeft; var y = event.clientY - drawingCanvas.offsetTop; context.fillRect(x, y, 5, 5); }}I changed to this, it works, but there's an issue. I'm trying to make a mini drawing application, so I need it to work like MS Paint, when the mouse is down and moving it draws a line.There's an issue though because it's not smooth this way, I have to keep releasing the mouse and pressing it again.
function checkmouse(event){ window.onmousedown = mousedown; function mousedown() { var x = event.clientX - drawingCanvas.offsetLeft; var y = event.clientY - drawingCanvas.offsetTop; context.fillRect(x, y, 5, 5); return false; }}
var drawingCanvas = document.getElementById('mycanvas');if (drawingCanvas.getContext){ var context = drawingCanvas.getContext('2d');}function main(){ }function checkmouse(event){ window.onmousedown = mousedown; window.onmousemove = mousemove; function mousemove() { return false; } function mousedown() { var x = event.clientX - drawingCanvas.offsetLeft; var y = event.clientY - drawingCanvas.offsetTop; context.fillRect(x, y, 5, 5); }}