Jump to content

Changing controls to mobile


Gods
 Share

Recommended Posts

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 (KEY_STATUS.space && player.dy === 0 && !player.isJumping) {  player.isJumping = true;  player.dy = player.jumpDy;  jumpCounter = 12;  assetLoader.sounds.jump.play();}// jump higher if the space bar is continually pressedif (KEY_STATUS.space && 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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...