Question

I am trying to achieve a simple throw effect in as3:

I put my finger on the screen and then swipe it as if I throw an object. The goal is to simulate a ball movement according to the swipe (direction, speed)

What gesture should I use? I tried TransformGestureEvent.GESTURE_SWIPE But this just give me the direction (left right, top, bottom) and no velocity or force or speed.

regards

Was it helpful?

Solution

There are many libraries and frameworks that handles touch input and can process complex gestures, you can google for them and find many easily.

You can also write your own, simple input processor that will give you the desired info.

On touch begin set values to 3 variables:

  • start x
  • start y
  • timestamp

Get the starting position be either the screen global position (you can access it from the TouchEvent object on your handler) or on the InteractiveObject (e.g. Sprite) mouseX and mouseY - that will give you relative position.
Timestamp can be easily taken with getTimer(), also the fastest way to get timestamp in Flash.

On touch end get other 3 variables

  • end x
  • end y
  • end timestamp

Knowing the difference of x and y positions and the time spent to make a gesture you'll be able to find the desired data - angle (using trigonometry or Math.atan2()), velocity, speed, force (by distance between x,y or time delta or both)

Hope that answers your question!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top