as3 touch - analysing long touch gesture - actionscript-3

I am making a musical instrument (mobile) where I have a rectangle that listens to user touch gestures . I would like to analyse the angle of the finger movement and play a short mp3 file in respond. I was researching and found a few options to use where I listen to the touch_end event and calculate the angle, however what I would like to accomplish is listening to one long swipe (going up , down, sideways etc.) and playing sounds accordingly.
Use case - user touches centre of the rectangle , swipes upwards , to the right , down (without removing finger) : output - playing upSound.mp3 , playing rightSound.mp3 , playing downSound.mp3 .
putting it together (should be fast gestures):
swipes upwards : playing upSound.mp3 ,
to the right: playing rightSound.mp3
down (without removing finger) : playing downSound.mp3
user ends gesture by removing finger.
My question- is there any library or tutorial that might help me accomplish this task .
Thanks

This may help you find that gesture angle

Related

ActionScript3: How to "offset" playing of sound object(with multiple objects playing at same time)

I want to make a program where you arrange sound samples. A cursor plays the sound it sweeps over and there can be many sound samples played at once. I want the user to be able to change/intterupt the playing(aka cursor progress) with a mouse click(similar to a progress bar).
I understand there are some ways of playing multiple sounds files at once, but thats not the problem. I wonder how I can play a sound sample from an offset when a click interrupt is generated.
Which AS3 class should I look at? Any other tips are appreciated.
You can use Sound.play() supplying the offset in milliseconds. You should first calculate the offset by measuring mouse position vs the progress bar, then stop the sound if it's playing, then call theSound.play(yourOffset) and you should be set.

Starling pauses when mouse leaves the stage area

I have just started using starling (framework based on stage3d) and i am working on a simple ping pong game.
What my problem is the moment my mouse leaves the stage area everything just stops and resumes working when the mouse enter the area again. I guess this is some feature in the framework but how can i control it... is there some kind of event being fired..?? or is there some way to stop this feature ??
If its relevant i am using the 'TouchEvent.Touch' event and using the 'moved' phase. Any other details if required i am ready to provide....
Thanks. :-)
Ok i finally got the solution from the official starling forums.
As my mouse left the stage my 'touch' was getting null... hence the whole 'pausing' of game code.. I don't know why i didn't get an error of some kind.
Still if someone is facing something similar.. might check ur values are not null...

ActionScript: fruit ninja swipe

I'm trying to build the fruit ninja type swipe to some of my buttons in Flash CS6 and ActionScript3.
In trying to figure it out this is what I have come up with:
get the coordinates of where the user first put his finger mouse down,
then where we lifted it
see if your button touches any of those coordinates (if yes, execute that button code)
run some kind of animation between the first two coordinates (mouse down, mouse up points)
am I on the right track?
Also, has anyone already done this so that I can look at their code?
Thanks!
Check out this series on the subject by the great Emanuele Feronato, using the physics library Box2d:
Slicing, splitting and cutting objects with box2d
Part 2: Actually split the object
Part 4: Using real graphics
(I couldn't find part 3 but I don't think we're missing anything too important there). Hope this helps!

Flash - SideScroller Turret Math

I'm working on a side scroller, and for the enemy I'm making a turret. I'm trying to make the turret aim at the player but I cant seem to get it right. Below is a rough sketch of what I want to achieve:
I want the barrel (dark blue), to aim/rotate to its pointing at the player.
I have uploaded a YouTube video of my scene:
http://www.youtube.com/watch?v=eeP47VoX9uA&feature=youtu.be
This is what I have so far (loop):
function enterFrameHandler(e : Event) : void{
_turretBarrel.rotation = Math.atan2(enTarget.x, enTarget.y) * 180/Math.PI;
}
What this does is only rotate the barrel when I jump, and the barrel isn't even aiming at the player, also the barrel doesn't change rotation when I walk on the other side of the turret.
My enTarget.x is always central to the stage and the scene (including the turret) moves around the player left and right (x)... Only the enTarget.y moves (jump/high platform).
I'm slightly new to Flash and ActionScript. If anyone could help me out, or point me in the right direction then that would be great.
Thanks
1) Make sure you got the right numbers and the position of the avatar and the turret are in the same coordinate space. A simple trace of each would do. In this case you probably want the world (relative to stage) position of both clips. Make sure they make sense compared to top left corner of the screen (0, 0).
2) Remember that _turretBarrel.rotation is a rotation that ranges from -180 to 180 so this would need to be taken into consideration when calculating angles.
3) Make sure you use the corresponding degrees/radians where appropriate.
4) force focus on avatar, run the game and see if the bounds looks ok. Then do the same thing with the turret.
Another good thing in general for debugging purposes is to setup some kind of debug graphics. i.e. draw a line of what you think is the direction vector to verify your numbers and calculations.
On a side note:
This is what the majority of programming is; Debugging. Assume nothing but hard facts, get your numbers from the debugger (probably quicker), or trace output. If you're still using the horrible flash professional IDE. I would really recommend getting one with a proper debugger like FlashDevelop (free) or Flash Builder (commercial)
Oliver, it looks like you are calculating the tangens of wrong angle (between player and X-axis). You need something like the following:
function enterFrameHandler(e : Event) : void{
_turretBarrel.rotation = Math.atan2(enTarget.x - barrel.x, enTarget.y - barrel.y) * 180/Math.PI;
}

going left: unrestricted / wrapping mouse tracking? in Flash?

So, I'm shooting up dudes in [3D Game], and I can keep dragging my mouse to turn left round and round.
Is this possible in Flash? Or have I misunderstood how the mouse is handled within [operating system] and then passed to the Flash Player?
As far as I am aware, you cannot lock the mouse to the flash window for security reasons - if you could, imagine the flash ad nightmare!
However, Flash does track the mouse position if it does move outside of the window frame. You just have to watch out for clicking - you might have to remap fire to the CTRL key or something.