Latest Uploads
Extraterre ... .0.1 (zip)

dantheman363

Monty Teas ... Screenie 1

steve_ancell

Santa Clau ... ed his bag

waroffice

manic_platdude.png

spinal

Tetris Clone

steve_ancell

Super blues bros.

spinal

Forum Home

Value clipping help

UserMessage
Posted : Saturday, 20 February 2010, 09:50 | Permalink | Mark Here
HoboBen


WW Entries : 9
I think I'm too sleepy, can't get this to work...

For a slider gui element, I want to clip the slider to certain values, e.g. every tenth of the bar.

This works:

offset = offset - (offset mod (width/(divisions-1)))

However, this always clamps to the lower value. I'd like to clamp to the nearest value, meaning sometimes I need to clamp upwards.

Any ideas?

-----
github
Posted : Saturday, 20 February 2010, 12:05 | Permalink | Mark Here
JL235


WW Entries : 7
Something like...
-->
is what I think would work.

Index refers to which of the sections the slider is located in, from 0 (inclusive) to divisions (exclusive).

So if the width is 100, and there are 5 divisions, then the increment is 20. The first position (at index 0) is 10 (20/2 + 0*20) whilst the last position (at index 4) is 90 (20/2 + 4*20).

Hope that helps!


-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Saturday, 20 February 2010, 12:34 | Permalink | Mark Here
HoboBen


WW Entries : 9
Thanks very much!

I managed to work on it and got this

-->


Result!!!



-----
github
Posted : Saturday, 20 February 2010, 16:00 | Permalink | Mark Here
Sticky


HoboBen -->


Do you really need the else of the if-then-else there? Setting a value to itself is effectively a no-op.

-----
last.fm
Posted : Sunday, 21 February 2010, 00:33 | Permalink | Mark Here
Jayenkai


WW Entries : 103
It was probably a leftover from a trial+error thing. I leave loads of those things all over the place!

-----
Posted : Monday, 22 February 2010, 10:52 | Permalink | Mark Here
HoboBen


WW Entries : 9
Oops, turns out it's "slider.sliOffset = slider.sliOffset - o3"... don't know how that disappeared!

-----
github
Latest Posts
Musical Tastes
rockford Sat 06:50
FIRST!!!
Hotshot Sat 06:08
Coder's Block
Jayenkai Thu 09:01
Consumer Lockout
9572AD Thu 06:09
Professor Oak, Honest!!
spinal Wed 23:24
Position in Mind
steve_ancell Wed 20:11
Sonic Adventure v0.x
Jayenkai Wed 07:08
Noel's Graduation
waroffice Wed 02:55
Monkey vs iOS tweaks
spinal Tue 22:51
Fucking Pound Sign Unicode Bullshit Bollocks
Dabz Tue 13:00
More

Latest Items
News : Newsletter #176
Jayenkai Sat 04:49
News : Newsletter #175
Dabz Tue 09:38
Blog : Snow: More Material Junk
Cower Sat 23:17
Dev-Diary : Mutant Monty: Amstrad CPC to Windows conversion
rockford Fri 13:14
Techy : AppleTV
Jayenkai Thu 09:40
Blog : Graphviz
steve_ancell Sat 14:17
Pets : Top-Down Shadow Hack
Jayenkai Tue 05:52
Snippet : JNKrunch v1.0
Jayenkai Sat 07:20
News : Newsletter #173
waroffice Fri 04:47
Blog : Material Loading
Cower Fri 02:08
Pets : I Done Won A Thing
shroom_monk Sun 11:31
Pets : Repurposing A Lexer
Cower Mon 22:06
Bah : Feeling a Little Angry
spinal Mon 11:26
News : Newsletter #170
Dabz Sat 00:34
Showcase : sbfgen
Cower Sat 16:57
More

Who's Online
spinal
Sat, at 09:13
CodersRule
Sat, at 09:12
rockford
Sat, at 09:05
shroom_monk
Sat, at 09:00
Hotshot
Sat, at 08:26
Jayenkai
Sat, at 08:23
9572AD
Sat, at 08:15
steve_ancell
Sat, at 06:06
therevillsgames
Sat, at 04:45
Mog
Sat, at 00:26
Link to this page
Site : Jayenkai 2006-Infinity |
MudChat's origins, BBCode's former life, Image Scaler.