Jump to content

Add touch screen function into JS Doodle Jump mobile game


Hester
 Share

Recommended Posts

I am currently working on Doodle Jump game. I want to add touch screen function so that the player touch the right side of the screen, the doodle move to the right and vice versa. 

How can I add invisible collider for both right and left side using javascript?

And how to write the function so that the touch screen function works on mobile?

Link to comment
Share on other sites

I don't mean to sound flippant but https://developer.mozilla.org/en-US/docs/Web/API/Touch_events, literally the first place you should check and probably first in a quick google search for 'JS touch events'.

The touch events are akin to mouse events, theres a down, a move and an up. They differ because there can be multiple touches, but, by and large, its the same. Microsoft are even working on unifying the events so we can just use pointer events and almost forget whether thats touch or mouse.

Just add elements to the right and left of the screen with touchdown handlers and you'll get the behaviour you want. If you're using canvas then many libraries allow you to add event handlers to elements (sprites, containers etc) in the exact same fashion.

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...