Adding in increments of .25 while dragging

Get help using Construct 2

Post » Tue Jun 24, 2014 10:31 pm

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.
B
87
S
44
G
16
Posts: 1,002
Reputation: 17,932

Post » Tue Jun 24, 2014 11:04 pm

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.
B
46
S
14
G
7
Posts: 603
Reputation: 8,116

Post » Tue Jun 24, 2014 11:15 pm

Hrmm, doesn't seem to be working,
here's the capx i made.

https://db.tt/l6r74XHk
B
87
S
44
G
16
Posts: 1,002
Reputation: 17,932

Post » Tue Jun 24, 2014 11:16 pm

I'd like it to be able to round to quarter increments, eg: 1.25, 1.5, 1.75
B
87
S
44
G
16
Posts: 1,002
Reputation: 17,932

Post » Wed Jun 25, 2014 1:24 am

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.
You do not have the required permissions to view the files attached to this post.
B
46
S
14
G
7
Posts: 603
Reputation: 8,116

Post » Wed Jun 25, 2014 6:20 pm

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.
B
87
S
44
G
16
Posts: 1,002
Reputation: 17,932


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 58 guests