How do I define dragging area?

Get help using Construct 2

Post » Sun Mar 18, 2018 1:00 am

Hello.
I have a joystick in my game that is working with no problems.
Now, what I want to do is settling the dragging area, right now, it doesn't matter where I drag the stick, it will just follow wherever I touch.

So I want to define the stick a specific area that the stick couldn't get out of.

This is the stick

Image

And I want it to not be able to get out of this area

Image

But, when I'm out of this area with my finger (or mouse), I want the joystick to keep dragging the stick, so I could get the angle from the joystick virable, but the stick won't bother the player while he's dragging the stick (whenever the player is dropping the stick, he gets back to the original spot.)

Thanks!
B
7
S
1
Posts: 17
Reputation: 411

Post » Sun Mar 18, 2018 2:36 am

Here you go:
https://www.dropbox.com/s/h67nu1sqfome3 ... .capx?dl=0


You can replace event #2 with this:
Small->Set position to Big
Small->Move at angle (angle=a, distance=d)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
155
Posts: 2,201
Reputation: 82,483

Post » Sun Mar 18, 2018 1:18 pm

dop2000 wrote:Here you go:
https://www.dropbox.com/s/h67nu1sqfome3 ... .capx?dl=0


You can replace event #2 with this:
Small->Set position to Big
Small->Move at angle (angle=a, distance=d)


Thank you very much!
B
7
S
1
Posts: 17
Reputation: 411

Post » Sun Mar 18, 2018 1:31 pm

dop2000 wrote:Here you go:
https://www.dropbox.com/s/h67nu1sqfome3 ... .capx?dl=0


You can replace event #2 with this:
Small->Set position to Big
Small->Move at angle (angle=a, distance=d)



Hey, I was trying to do the same like that
Image

But it doesn't work, maybe becuase of something that is written here?
Image


Thanks for your time

Edit: I have 2 joysticks in the game if that matters
B
7
S
1
Posts: 17
Reputation: 411

Post » Sun Mar 18, 2018 1:44 pm

You can't use drag&drop on the same sprite.
Create another (invisible) sprite with Drag&Drop behavior, say "dragSprite".
Remove Drag&Drop behavior from the "sangStick".

Change events to this:

dragSprite is dragging -> set AreaAngle to angle(sangPad.X, sangPad.Y, dragSprite.X, dragSprite.Y)
.................set AreaDistance to distance(sangPad.X, sangPad.Y, dragSprite.X, dragSprite.Y)

The rest is the same.
When not dragging, return both sangStick and dragSprite to sangPad posision.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
155
Posts: 2,201
Reputation: 82,483

Post » Sun Mar 18, 2018 1:59 pm

dop2000 wrote:You can't use drag&drop on the same sprite.
Create another (invisible) sprite with Drag&Drop behavior, say "dragSprite".
Remove Drag&Drop behavior from the "sangStick".

Change events to this:

dragSprite is dragging -> set AreaAngle to angle(sangPad.X, sangPad.Y, dragSprite.X, dragSprite.Y)
.................set AreaDistance to distance(sangPad.X, sangPad.Y, dragSprite.X, dragSprite.Y)

The rest is the same.
When not dragging, return both sangStick and dragSprite to sangPad posision.



Shouldn't that work?
I don't really understand why I need to use a second sprite to define the drag, the drag also define me the conAngle that defines the player movement, there's no way to use the same drag and drop that I already have?

Image

something like that
B
7
S
1
Posts: 17
Reputation: 411

Post » Sun Mar 18, 2018 2:23 pm

If you move the finger outside the sangPad, dragging will be interrupted, because sangStick can't move further.
That's why you need a separate invisible sprite that can be dragged freely.
It's a popular trick, you can see an example here:
how-do-i-successfully-make-a-span-class-posthilit-slider-span-fx-bo_p1153790?#p1153790
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
155
Posts: 2,201
Reputation: 82,483

Post » Sun Mar 18, 2018 2:38 pm

dop2000 wrote:If you move the finger outside the sangPad, dragging will be interrupted, because sangStick can't move further.
That's why you need a separate invisible sprite that can be dragged freely.
It's a popular trick, you can see an example here:
how-do-i-successfully-make-a-span-class-posthilit-slider-span-fx-bo_p1153790?#p1153790


Oh, now I understood what you meant!
Successfully did it, thank you very much :)
B
7
S
1
Posts: 17
Reputation: 411


Return to How do I....?

Who is online

Users browsing this forum: Cassianno, dioking, repkino and 2 guests