Dragging rotation

Get help using Construct 2

Post » Fri May 03, 2013 4:37 am

Hi again..

I have an object, that is setting its angle to: is in touch-->touch.x, touch.y .

It works fine, but when I lift my finger and place it again on screen, the object angle resets as it should hold the angle that it had when the finger stopped touching..

I think I have seen a forum post about something similar, but of course I'm not able to find it as I need it..

Help appreciated!!

CAPX LINK
B
10
S
2
Posts: 27
Reputation: 1,231

Post » Fri May 03, 2013 6:58 am

Hey Chef

Here is a quick and simple example of how to achieve what you want (I'm sure there are more elegant solutions).

http://db.tt/PX8ODfd1

To explain,

I created a "Moved" variable and made it that ONLY when the variable is less than 2, move the ball to the touch angle. As the ball gets moved the variable also switches to 1.

As you see the next event registers when the variable is 1 and touch is inverted (I.E not touching) and the action sets "Moved" to 2 so that it wont be able to move again.GenkiGenga2013-05-03 06:59:39
ImageImage
B
73
S
16
G
6
Posts: 1,038
Reputation: 10,473

Post » Fri May 03, 2013 9:28 am

Hi there,
@ GenkiGenga, I was very interested in your example and downloaded it. I made few changes because the button was turning wherever the touch accured on the screen. So I make it happen only when the button is touched. I also made some changes with the variable because once turned, the button couldn't be moved again.
But I still have one problem : when the button is touched, it immediately goes into one direction before being able to rotate as wished.
Do you know a way to correct that ?
Thanks !
https://www.dropbox.com/s/eh88sa6wapizbvg/Touchexample2.capx
B
20
S
9
G
4
Posts: 197
Reputation: 4,080

Post » Fri May 03, 2013 9:51 am

Hey Laurent,

http://db.tt/Aw33TdwT

The problem was because the line you drew is actually running on the left hand side of the circle (objects face the right in the editor). I've rotated your circle (in the edit animations window) so that the line now faces the right so it lines up wherever the mouse is clicked. Is that what you meant?
ImageImage
B
73
S
16
G
6
Posts: 1,038
Reputation: 10,473

Post » Fri May 03, 2013 11:43 am

@ GenkiGenga, looks great now, thanks !
B
20
S
9
G
4
Posts: 197
Reputation: 4,080

Post » Fri May 03, 2013 1:54 pm

No worries ;)
ImageImage
B
73
S
16
G
6
Posts: 1,038
Reputation: 10,473

Post » Fri May 03, 2013 2:15 pm

Hey, thanks for the posts! But this still doesn't fix what I was after.. Maybe I wasn't clear enough.

I was looking for a way to "store" the angle of the object, so that when you want to rotate it again, it would move from the angle it was set when the touch ended.. Now as you can see from these great examples, it still jumps to the angle of touch before it starts to rotate.

Is this a case for local variables..? I'm still a "semi-noob" to construct and really haven't looked into them yet.
B
10
S
2
Posts: 27
Reputation: 1,231

Post » Fri May 03, 2013 3:35 pm

Oh you wanted it to rotate to where the mouse is?

Try this link again.

http://db.tt/PX8ODfd1

It now rotates to where the mouse is when touching, if you only want to click once then you can create a marker sprite where you click the mouse and then set the angle to that instead of Touch.X, Touch.YGenkiGenga2013-05-03 15:36:11
ImageImage
B
73
S
16
G
6
Posts: 1,038
Reputation: 10,473

Post » Fri May 03, 2013 4:04 pm

Umm...Well..No.. :)

The first link I posted is rotating the object how I wanted.

I'll try to explain once more and if I'm not clear enough now, i'll lock myself up for a month and challenge C2 for a last-man-standing duel!

In the capx I posted:

The object is facing 0-degrees, as a default by C2.
As I touch/hold mouse, the object angle follows touch/mouse..

It's all good if I put my finger/mouse back to the exact same angle where it was when I stopped touching and then drag. But if I start to drag from, let's say the start of layout and the object is still 0-degrees. I place my finger to the left side of the screen, the object angle snaps to touch.x, touch.y and then it follows the touch..This is not what I'm looking for..

I would like to see the object rotate from the angle it was left after touch or start of layout, no matter where I place my finger on the screen.


**crossing fingers**



B
10
S
2
Posts: 27
Reputation: 1,231

Post » Fri May 03, 2013 4:25 pm

Did you download the example in the last post? Its the same link but I had updated it.

What you should be seeing is the ball rotating to where you hold the mouse, click and hold somewhere else and it rotates from its end position to your new angle.

In your example you have the object angle set to your mouse, that's why it snaps to the location and follows the mouse so crisply. If my example is rotating too slowly then change the degree value from 1 to 3 etc and it will speed up to the same effect.GenkiGenga2013-05-03 16:28:24
ImageImage
B
73
S
16
G
6
Posts: 1,038
Reputation: 10,473

Next

Return to How do I....?

Who is online

Users browsing this forum: Pandadoor, Zebbi and 18 guests