Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / 'Drag' event on iPad or iPhone - GetRawTouchType( iIndex )

Author
Message
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 8th Feb 2012 11:00
Hi All, Can anyone help with the AppGameKit command GetRawTouchType( iIndex )?

I want to detect a 'Drag' event but there is no mention of the TouchType Indexes for hold, short touch or drag.

I want to move my sprite left or right depending on the drag direction...

Any ideas please.

Thanks

Ruddster
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Feb 2012 15:45
Try running this and test the results of various touch events. Can't test right now but I think it should get you the answer:


Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 8th Feb 2012 15:57
Thanks Baxslash,

I have it fully working now..

I have written code to detect the 'drag' direction, how far in pixels the drag is and apply a speed to the sprite relative the drag distance...

When the touch is released I then velocity damp to quickly slow the sprite...

Excellent!
Trisect Development
22
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Denmark
Posted: 8th Feb 2012 21:41
Can we see your code?

iOS Apps from Trisect Development.
Click here.
Trisect Development
22
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Denmark
Posted: 13th Feb 2012 22:58
I really would like to see your code if its possible.

iOS Apps from Trisect Development.
Click here.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Feb 2012 08:27
I'll cover multitouch in an upcoming Bitesize tutorial if that helps?

Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 14th Feb 2012 09:24
Hi Trisect, sorry been busy testing various touch input coding for controlling position of animated sprites.

I am developing a new game for the iPad and iPhone where you can move a character left or right and throw a 'missile' upwards. I thought it would be good to move the charatacter by simply draging the finger left or right and the code below enables this.

The animated sprite 'pok' can face left or right and animates in either direction, hence the current frame detection. Basically this section of code detects the first touch X and compares the new 'drag' X to the first touch X. This provides either a positive or a negative value which is used as the SetSpritePhysicsImpulse vlaue that moves the sprite. I have since changed the code to use SetSpriteVelocity to move the sprite and link the velocity value to the animation speed.

I also added code later (not shown here) to detect a double tap on the screen enabling a 'fire' sequence.

PROBLEM THOUGH! Whilst my code worked great and I refined it to give smooth animation, slowing down control and animation direction detection.... It proved to difficult to use in an actual game! It was difficult to hold the iPad or iPhone and drag the screen and double tap to fire. Even with a fire button added the drag left or right was awkward to use. I will file the code for use in another game.

I tried using virtual buttons for left or right control, however you must remove you finger completely from one button before another button touch can be detected.... I am thereforew now using screen area detection to simulate button pressing but I can slide the finger left or right to select either left or right movement.

Hope all this helps?


[touchID=getrawfirsttouchevent(1)

If touchID > 0
result=GetRawTouchType(touchID)
If result = 3
If GetRawTouchStartX(touchID) > GetRawTouchCurrentX(touchID)
leftspeed = (GetRawTouchCurrentX(touchID) - GetRawTouchStartX(touchID)) * 100
SetSpritePhysicsImpulse(pok,GetSpriteXByOffset(pok),GetSpriteYByOffset(pok),leftspeed,0)
If GetSpriteCurrentFrame(pok) < 7
SetSpriteFrame(pok, 6)
PlaySprite(pok,20,1,7,10)
Endif
Endif

If GetRawTouchStartX(touchID) < GetRawTouchCurrentX(touchID)
rightspeed = (GetRawTouchCurrentX(touchID) - GetRawTouchStartX(touchID)) * 100
SetSpritePhysicsImpulse(pok,GetSpriteXByOffset(pok),GetSpriteYByOffset(pok),rightspeed,0)
If GetSpriteCurrentFrame(pok) = 1 OR GetSpriteCurrentFrame(pok) > 5
SetSpriteFrame(pok, 1)
PlaySprite(pok,20,1,2,5)
Endif
Endif
Endif
If GetRawTouchReleased( touchID ) = 1
SetSpritePhysicsDamping(pok, 7)
Endif
Endif]
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 14th Feb 2012 11:28
+1 for multitouch tutorial
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 14th Feb 2012 16:42
@baxslash I can provide a head start if you like, I wrote some code to test multi-touch a while back, but it's not well documented...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Feb 2012 17:19
Thanks Paul! I have a couple of quick games I started. One is a two player called flick pong and another is a finger twister game. Both require some kind of storage of data which would be useful to share. Also I recently wrote some pinch-zoom code that might be handy.

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 14th Feb 2012 23:11
Thanks PAUL, your code is very self explanatory
JORGEMAL
15
Years of Service
User Offline
Joined: 2nd Aug 2009
Location:
Posted: 29th Feb 2012 16:40 Edited at: 29th Feb 2012 16:45
I reviewed the first code snippet for drag detection and I see that GetRawTouchType() returns a value of 3 when drag is detected, a value of 2 if my finger remains pressing, otherwise it returns zero which I suppose refers to a short touch. How can I distinguish between a single-touch and a double-touch?

With respect,
Jorge Maldonado
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 1st Mar 2012 16:15
0 actual refers to a touch that has yet to be determined, could be a short, long, or drag depending on what happens next. A type of 0 is guaranteed to become one of the other types 1,2,3 so you can ignore it until then if you like. Short is type 1.

A double touch would register as two short touches in quick succession. So you could setup a timer that starts when you detect a short touch and then when you get another short touch check if the timer is still running. Or if the timer reaches 0 you can assume it was a single touch.

Login to post a reply

Server time is: 2024-11-23 05:05:37
Your offset time is: 2024-11-23 05:05:37