How do I make this kind of movement?

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I have a graphic background grid (10x14, each square is 32x32 pixels) and a falling pieace (like tetris).

    Right now, I'm controlling the piece with the keyboard. So when the user hits right key, the piece moves 32px to the right, when it hits left key, 32px to the left. I want to have the same thing, but with mouse/touch. When someone touchs the piece,can move 32px to the left, to the right or down. But if I put draggable behavior to the sprite, the user can take wherever he wants.

  • Take a look at the example file on my last post here:

    The player must click/touch the sprite then drag to get the piece to move but does not get to drag the piece around. The click and drag just sets the direction the piece moves.

    I hope it gets you what you need and good luck with your project.

  • I saw your code and now I got this. The thing is that works for moving right but not for moving left!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There are a few things missing.

    You are not registering the location the touch ended. In the events 32 and 33 System->compare 2 values, the touch.x is the initial touch location because it is in an on touch event, not the touch end location which would be registered in the on touch end event. This is needed to define which direction the player dragged their finger.

    In my example under event 2, I am storing the position from the on touch event so I can compare it with the position from the on touch end event. In event 3, I am using an on touch end event to get the direction. Because you are only allowing left and right movement, you will change that event to simply check if Touch.X (which is now the position the touch ended since we are accessing the value in the on touch end event) is greater or less than Block.X and move the piece accordingly. If Touch.X is greater, move it left. If it is less, move it right.

    [Edit] I just went back and read through your original post again and realized you are not just allowing for left right movement. So, you will need to look back over event 3 and learn how sub events 4 and 7 are defining the direction.

    Of course, if the above appears too difficult, you could always draw an on screen directional pad and wire each direction in the same way you wired in the keyboard.

  • Ok, got it! I got also to update the tStart every time I move because I want a constant move, like a custom drag and drop, and not moving when I release the button!

    Here's the working result! Thanks!

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