Touch and Mouse controls

Discussion in 'Game Development (Technical)' started by God, Jan 1, 2015.

  1. God

    God New Member

    Mar 7, 2014
    Likes Received:
    I am sure everyone who wanted there HTML5 game to work mobile had this problem. So I have my controls set up as space bar to jump but I want my HTML5 game to work everywhere so I need to change it to mouse/touch. Mouse/touch doesnt have a keycode so whats the most optimal way to do it for this code? Do I need to do mouse and touch separately?

    if ( && player.dy === 0 && !player.isJumping) {
      player.isJumping = true;
      player.dy = player.jumpDy;
      jumpCounter = 12;;
    // jump higher if the space bar is continually pressed
    if ( && jumpCounter) {
      player.dy = player.jumpDy;
    I have read a lot of tutorials on this and it seems like its going to be a lot of code I just want to know what html5 devs do so I dont write bad JS code. Its not a simple KeyCode for mouse or something. So how does this code snippet look like if Jump is set to mouse/touch? Anyone have code they can share?

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer