[Suggestion] Touch Plugin

Discussion and feedback on Construct 2

Post » Wed Jul 17, 2013 8:18 pm

Hi,

Another suggestion (:

Here is the situation: I had to implement some virtual joystick system for smartphones.
The idea was to have two joysticks, a left one to move a character, and a right one to aim and shoot.

And here is how it seemed natural to proceed:
[code]Global number rightID = -1
Global number leftID = -1
+ on touch start
   + leftID = -1
   + Touch.X < scrollx
      -> set leftID to Touch.TouchID
   + rightID = -1
   + Touch.X >= scrollx
      -> set rightID to Touch.TouchID
+ on touch end
   + Touch.ID = leftID
      -> set leftID to -1
   + Touch.ID = rightID
      -> set rightID to -1[/code]
Then I can track the position of the left and right finger
The only issue is that the Touch.X expression (as well as the Touch.Y) will always give you the position of the first touch
Here is the proof in the js code:
[code]Exps.prototype.X = function (ret, id, layerparam)
{
   ....
   ret.set_float(layer.canvasToLayer(this.touches[0].x, this.touches[0].y, true));
   ...
}[/code]

The work around I used was to get the last touch using the touch index like this:
[code]+ on touch start
   + leftID = -1
   + Touch.XAt(Touch.TouchCount-1) < scrollx
      -> set leftID to Touch.TouchID[/code]

So my suggestion would be to:
- either make Touch.X return the position associated with the trigger it's used in, and fall back to the first touch outside of a trigger context (that's already the case with TouchID and TouchIndex I believe)
- or create a Touch.LastTouchX expression

(I prefer the first solution (: )Yann2013-07-17 20:19:46
B
63
S
22
G
14
Posts: 1,482
Reputation: 16,432

Post » Wed Jul 17, 2013 8:55 pm

This was the reason that touch.forID was made for. I had the same problem last year.

touch.id counts number of touchs
touch.forid is the specific touch instance and remains constant.

so also I think it's
touch.forIdAtXY( )
B
88
S
18
G
9
Posts: 2,455
Reputation: 14,928

Post » Thu Jul 18, 2013 6:35 am

@jayderyu
Ah yeah indeed
I could have done [code]Touch.XForID(Touch.TouchID)[/code]But still, I wonder why the Touch.TouchID and Touch.TouchIndex correspond to the last touch, but Touch.X is kinda forced to always be the first finger's position.
To me, it would make more sense to put in the instanceProto.onPointerStart function[code]this.trigger_x = touchx
this.trigger_y = touchy[/code]And us those for the Exps.prototype.X and Exps.prototype.Y functionsYann2013-07-18 06:41:07
B
63
S
22
G
14
Posts: 1,482
Reputation: 16,432

Post » Thu Jul 18, 2013 7:34 am

When I made my touch joystick system, I had a bottom object and a top object that was moving towards where the collision polygon touch was detected(is touching object "a"), within a maximum distance. The distance and x,y between these two objects was adjusting direction and speed for my character. So touching objects gave them unique ID's.
B
42
S
5
G
5
Posts: 407
Reputation: 5,711

Post » Thu Jul 18, 2013 8:00 am

@nemo
Yeah, well, I actually wanted a virtual joystick that would appear where you first touch (:
Kinda relative stick

I indeed made another version with fixed buttons so I can just do a "on object touched" and capture the TouchID without having to check the touch.X value.

But with a relative stick, I need first to check if it's on the left or right of the screen to know if it's the left or right stick.
B
63
S
22
G
14
Posts: 1,482
Reputation: 16,432


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 11 guests