Drag and drop - limit screen area

0 favourites
  • 7 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • Hi all,

    I have an object that I can drag around the screen. I have set its behavior to be bound to the layout and that stops it leaving which is great. My issue is part of my layout contains a hud and I wanted the same kind of restriction to stop it being dragged over that.

    I have tried putting a transparent sprite there as a wall and playing with various different parameters but that doesn't seem to help. Any pointers would be amazing.

    Thanks <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Replace the drag and drop behaviour by your own events.

    I'm creating an example for you right now so I don't have to explain it, hold on a minute

  • Here you go.

    dl.dropbox.com/u/87237423/D%26D.capx

    Notes:

    dragX is the X position on the sprite of where the mouse took hold of the sprite. (can you figure out what dragY is? <img src="smileys/smiley1.gif" border="0" align="middle" /> )

    As soon as the mouse clicks on the object you want to drag & drop the local boolean PickedUp is set to true, as soon as the mouse releases the button Picked Up is set to false.

    First we test whether the mouse is within the area of where drag and drop-ing is allowed. If it is > we set the sprite to the Mouse.X en Mouse.Y.

    If its not, we test whether the mouse is too far to the right or whether it is too far down. In the first case we set the sprites x to the furthest allowed x and set the y to Mouse.Y. Second case works like this.

    Then, at last, we test if the mouse is both too far to left and and too far downwards, and we set the position of the sprite to the furthest allowed position.

    If you got any questions just let me know ;)

    PS: I too late realised I could use imagepoints (I used to make games with Gamemaker which has not imagepoints ;d), so these might be handier instead of using Sprite.height/2 etc (also only works when the origin is in the middle of the image!)

  • Thanks Jasper I really appreciate the effort you went to there! I'll have a go through your example and take it from there. *thumbs up*

  • Here you go.Notes:

    dragX is the X position on the sprite of where the mouse took hold of the sprite. (can you figure out what dragY is? )

    As soon as the mouse clicks on the object you want to drag & drop the local boolean PickedUp is set to true, as soon as the mouse releases the button Picked Up is set to false.

    First we test whether the mouse is within the area of where drag and drop-ing is allowed. If it is > we set the sprite to the Mouse.X en Mouse.Y.

    If its not, we test whether the mouse is too far to the right or whether it is too far down. In the first case we set the sprites x to the furthest allowed x and set the y to Mouse.Y. Second case works like this.

    Then, at last, we test if the mouse is both too far to left and and too far downwards, and we set the position of the sprite to the furthest allowed position.

    If you got any questions just let me know

    PS: I too late realised I could use imagepoints (I used to make games with Gamemaker which has not imagepoints ;d), so these might be handier instead of using Sprite.height/2 etc (also only works when the origin is in the middle of the image!)

    hey jasper, i can't download your example. please give me a link again please! thanks soooo much!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So on my application, I was able to use drag and drop pretty easily (build 206) to accomplish what I needed. In order to keep the sprite on page (my sprite size is 4000,647), all I did was add two events in my event sheet.

    1) Check if it's past the X axis (upper limit), if so just set it to the appropriate X value

    example: if X > 1983, set X to 1983

    2) Check if it's past the X axis (lower limit), if so just set it to the appropriate X value

    example: if X < -53, set X to -53

    This will block the user from scrolling my sprite past it's image limits and keep it bound to my 1920,1080 layout.

  • it's work so fine...

    (Object) is > x coordonate(ex 32): (Object) set x coordonate(ex 32)(

    same for Y

    the object stay in another object with this simple solution

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