0 Favourites

Adding in increments of .25 while dragging

  • I would like to figure out how to add increments to a value while dragging.

    1) Record the Y position of where a user starts dragging the mouse.

    2) As the user drags upwards, i want to keep track of a value, and every 20 pixels , it adds .25 to that value, and as they drag downwards, it subtracts .25

    3) when you let go, it records that difference and adds/subtracts from the current value of that item.

    Imagine you had a project button with an amount of hours you've spent working on it. as you drag upwards you would be adding time to that project, and down would subtract time until you release the button, in .25 increments.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Create a variable called startY, and set that to Mouse.Y when the user starts dragging the slider.

    When the slider is released set hours to hours + (((Mouse.Y - startY) / 20) * 0.25)

    Mouse.Y - startY gets the difference in pixels the slider has moved from start to finish.

    Then you get how many 20's are in that value, and multiply it by 0.25

    If you want to clamp the slider to a maximum/minimum value, replace Mouse.Y with Slider.Y and restrain that objects position.

  • Hrmm, doesn't seem to be working,

    here's the capx i made.

  • I'd like it to be able to round to quarter increments, eg: 1.25, 1.5, 1.75

  • Fixed the equation, added a modulus subtraction to get rid of the remainder, and also inverted the value so moving up is positive and down is negative. If you want to remove that, just take out the * -1. I believe this is what you're looking for.

  • Thanks EncryptedCow!!!!! This is exactly what i was trying to do, but i suck at math

    Is there a way to display the "change" value to always be 3 digits? eg: 2.00, 1.50, 0.25 etc.

    Zeropad seems to only add zeros the beginning of a number, and the formula i found for rounding off decimal places (str(int(balance))&zeropad(int(balance*100)%100, 2) seems to strip the zeros on the end.

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