Sliding movment of player with touch function

edited February 2017 in p5.js

First of all i am new to p5.js. So hopefully i am at the right place.

How to move player in x-axis with using touch function,here player can be any object drawn on the canvas. Now the problem i am facing that where ever i am touching player is poping up there but i want it to move/slide only when i slide my finger irrespective of on which part of screen i am sliding or touching. :)

Tagged:

Answers

  • edited February 2017

    @ssuman2 -- please provide example code for feedback -- and format the code in your post using CNTRL+o.

    It sounds like you are assigning the x,y of the player based on mouseX, mouseY (or the current touch point).

    Instead, you might want to do something like this:

    1. on touchStarted(), save the mouseX / mouseY (or current touch point) as originX, originY
    2. on touchMoved(), dragging is happening. compute the difference between the current mouseX / mouseY (or current touch point) as offsetX, offsetY. Display the player location shifted by the offsets.
    3. on touchEnded(), dragging is over. copy the offset values into the updated player location x/y, clear the offsets, and clear the origins.
Sign In or Register to comment.