4
Guys I have this code but I can’t get each mouse button to call a different function:
var tela = document.getElementById("tela");
var c = tela.getContext("2d");
c.strokeStyle = "black";
c.strokeRect(0, 0, 600, 400);
var atira = function(evento) {
var x = evento.pageX - tela.offsetLeft;
var y = evento.pageY - tela.offsetTop;
c.fillStyle = "blue";
c.beginPath();
c.arc(x, y, 10, 0, 2 * Math.PI);
c.fill();
};
var atira2 = function(evento) {
var x = evento.pageX - tela.offsetLeft;
var y = evento.pageY - tela.offsetTop;
c.fillStyle = "red";
c.beginPath();
c.arc(x, y, 10, 0, 2 * Math.PI);
c.fill();
};
tela.onclick = function(evento) {
switch(evento.which) {
case 1 :
console.log("botao esquerdo");
tela.onclick = atira;
break;
case 2 :
console.log("botao do meio");
tela.onclick = atira2;
break;
case 3 :
console.log("botao direito");
default:
console.log("mouse estranho");
}
};
Can also put your html? can be only the relevant part.
– Fernando Leal