How do I move left and right based on touch location?

0 favourites
  • 8 posts
From the Asset Store
Move Block
$10 USD
Captivating puzzle game. With challenging gameplay, this game will keep you very engaged.
  • How do I move left and right based on touch location?

    For example, if the player touches the screen on the left side, I'd like to move left and vice versa.

    I am not sure how to compare the

    current view's center x value

    to the touch position's x value (which I know is Touch.X).

    Thanks in advance for any help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi Leespiker IMHO, let's say you have layout size of 800 width and 300 height. add an empty sprite and set size to 400 (half size of the layout width) and height of 300. name it "leftside" and then duplicate it and name the other "Rightside". then you can add events like: ON "leftside" touched ==> action: "player" move left

  • Hi Leespiker IMHO, let's say you have layout size of 800 width and 300 height. add an empty sprite and set size to 400 (half size of the layout width) and height of 300. name it "leftside" and then duplicate it and name the other "Rightside". then you can add events like: ON "leftside" touched ==> action: "player" move left

    Right, I thought of that, but if the current view is not the whole screen (like on a mobile app), then if you were on the left side of the screen and clicked/touched, then you would move left even though you clicked on the right side of the "current view screen" since the player cannot see the entire map, just a small portion of it.

  • I could check if the touch position's x value is greater than or less than the player's current x value, but how would I go about checking that if statement?

  • You can compare Touch.X to scrollx.

    [attachment=0:3t8601xh][/attachment:3t8601xh]

  • I would make a "pointer" graphic for debug purposes and compare it's position. Make it invisible eventually, but It's always good to know where the touch is. It might be a bad idea, but that how I've done it in the past.

  • You can compare Touch.X to scrollx.

    [attachment=0:3npu9wyl][/attachment:3npu9wyl]

    Thank you. This is exactly what I needed.

    I did the following:

    Would you happen to know how to tell if 2 touches are currently being made?

    EDIT: Figured it out on my own.

  • Leespiker good for you that is how one learns

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