html5 - how to listen for a mouse click in a javascript game -


I am designing a game in JavaScript and I have a function that goes like this:

  function handle (mod) {if (in keys 37) in charge 65) {// left player.x - = player.speed * mod; } If (keys in 38) keys in Down (87) {// up player.y - = player.speed * mod; } If (keys in 39 keys) 68) {// true player. X + = player.speed * mod; } If the keys (40 in the keys) open the keys {83} {// player below Y + = player.speed * mod;   

And I want to add another conditional which calls my shoot () function when I click on the mouse. How can I write this condition so that it is similar to the code above because I I have seen that every tutorial just tells me to make clickable buttons and I need to use the addEventListener, which I do not think is what I'm trying to say to say the mouse coordinates C do where the shot is and use it as your html tag:

  & Lt; Html onclick = "shoot ()" & gt; & Lt ;! - Code - & gt; & Lt; / Html & gt;   

You can also use onclick on your canvas:

  & lt; Canvas onclic = "shoot ()" id = "game_pad" & gt; & Lt; / Canvas & gt;    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -