How do I make this kind of movement?

Get help using Construct 2

Post » Fri May 02, 2014 5:09 pm

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.
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 18
Reputation: 592

Post » Fri May 02, 2014 6:13 pm

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

viewtopic.php?f=147&t=103369

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.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Mon May 05, 2014 5:13 pm

I saw your code and now I got this. The thing is that works for moving right but not for moving left!
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 18
Reputation: 592

Post » Mon May 05, 2014 5:56 pm

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.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Thu May 08, 2014 6:34 am

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! :)
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 18
Reputation: 592


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests