How do I define dragging area?

0 favourites
  • 8 posts
  • 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

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

    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!

  • 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)

  • 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!

  • 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

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

    Thanks for your time

    Edit: I have 2 joysticks in the game if that matters

  • 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.

  • 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?

    something like that

  • 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:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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:

    Oh, now I understood what you meant!

    Successfully did it, thank you very much

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