[Suggestion] Touch Plugin

0 favourites
  • 5 posts
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • 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:

    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

    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:

    Exps.prototype.X = function (ret, id, layerparam)
    {
       ....
       ret.set_float(layer.canvasToLayer(this.touches[0].x, this.touches[0].y, true));
       ...
    }

    The work around I used was to get the last touch using the touch index like this:

    + on touch start
       + leftID = -1
       + Touch.XAt(Touch.TouchCount-1) < scrollx
          -> set leftID to Touch.TouchID

    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 (: )

  • 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( )

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • jayderyu

    Ah yeah indeed

    I could have done

    Touch.XForID(Touch.TouchID)

    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

    this.trigger_x = touchx
    this.trigger_y = touchy

    And us those for the Exps.prototype.X and Exps.prototype.Y functions

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)