jkl_69 Posted January 16, 2015 Share Posted January 16, 2015 HelloI wish to drag sprites only Vertical OR horizontal, therfore i have to detect if the Drag is more horizontal or vertical.How can i do this? Link to comment Share on other sites More sharing options...
rich Posted January 16, 2015 Share Posted January 16, 2015 Phaser has support for that built-in: http://examples.phaser.io/_site/view_full.html?d=input&f=motion+lock+-+horizontal.js&t=motion%20lock%20-%20horizontal and http://examples.phaser.io/_site/view_full.html?d=input&f=motion+lock+-+vertical.js&t=motion%20lock%20-%20vertical Link to comment Share on other sites More sharing options...
jkl_69 Posted January 24, 2015 Author Share Posted January 24, 2015 First thanks for your answer. But in this examples the sprits is ALWAYS locked for one Direction.My Intention is lock different axis each times when I start drag depends on the trend of movement. If I start drag the sprite mainly horizontally I will lock the vertical Movement and opposite. Link to comment Share on other sites More sharing options...
Daniel Belohlavek Posted January 24, 2015 Share Posted January 24, 2015 You could do the following (just an idea). Get the current pointer position.Define a variable to save past position and a variable to save the current direction.If the past variable is empty then ignore this step. If it has past results, compare them to the current pointer position. Which one changed the most, x or y?Update the direction with the result from the previous step.Update the past position with current position. Put that on a function and call it on update() Now you have a variable that contains the direction of the pointer position. Proceed to move the sprite on the desired axis. This is the first thing that came to my head, I haven't tested it. Please give it a try and tell me if it helped Good luck! Link to comment Share on other sites More sharing options...
Recommended Posts