Move player to touch

61 views
Skip to first unread message

ohblahitsme

unread,
Apr 8, 2014, 10:50:18 PM4/8/14
to haxef...@googlegroups.com
Hi,

I'm trying to figure out how to move the player exactly to the location of the latest touch. I've tried a few methods, but I've had some problems.

1. Tweening: I can set the player to tween to the touch, which I get from FlxG.touches.getFirst(). The problem is that if there are many touches in succession, the sprite skips around and moves after reaching the spot of the last touch.

2. moveTowardsTouch/Mouse: This method works, except that it doesn't stop once it reaches the location of the touch.

Any ideas on how to solve this?

Thanks!

SruloArt

unread,
Apr 9, 2014, 3:43:15 AM4/9/14
to haxef...@googlegroups.com
1. I don't get if you mean regular touches that you get from the user, or the bug that makes the touch register twice (I think it was solved?). What do you mean by "skips around"? When you give a lot of ending points to a tween, well, that's what happens. You need to use a delay (in ms) between touches, so the user can't change his mind or press the screen like crazy.
2. You can have a point variable that get the touch position when clicked, then create a hitbox around it, and delete the point (release it, as it's pooled) if the user touched somewhere else, or if the player sprite overlapped the hitbox (you can use a point for that, but it may be too small for the user on a small mobile screen).

Sergio

unread,
Apr 9, 2014, 3:44:23 AM4/9/14
to haxef...@googlegroups.com
I think that you should remember the tween object and update it (or not update it) with coordinate to which you want to move.


On Wednesday, April 9, 2014 5:50:18 AM UTC+3, ohblahitsme wrote:
Reply all
Reply to author
Forward
0 new messages