gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > "button slider" help

#147986 - jay001 - Mon Dec 31, 2007 2:04 pm

Im a begginer and i was wondering how to go about creating a slider button like the opacity slider in "colors".

The way i thought about doing this was making a sprite and set some boundries for it. is this the right way? if so can some one go into a bit more detail or just tell me a better way.

As i said before i am a begginer and only want to learn the best ways of doing things.
Thanks in advance.

#148002 - Peter - Mon Dec 31, 2007 4:57 pm

Maybe this helps you further:

_________________
Kind Regards,
Peter

#148079 - jay001 - Wed Jan 02, 2008 12:22 am

cheers mate, this is very helpfull.
edit: on closer inspection... maybe not.

#148115 - ant512 - Wed Jan 02, 2008 1:25 pm

Slider buttons are on the list for Woopsi, but that doesn't help you much now.

Simplest way to do this outside of a GUI framework is to:

- Define a rectangular region and perform a collision detection check against the stylus co-ordinates.

- If you detect a collision, and then the stylus moves, reposition the slider to match the stylus' X or Y position (depending on whether or not you want a horizontal or vertical slider).

- Each time you reposition the slider, trigger another function that updates whatever it is that the slider controls.

You can calculate the value of the slider by working with a few values. In the case of a 5-bit colour slider, we could asssume the following:

- Scroller is horizontal.
- Scroller is 100 pixels wide.

When the scroller is dragged to the left, the colour is 0. When the scroller is dragged to the right, the colour is 31. Therefore, calculating the "value" of the scroller in terms of colour is a matter of dividing its max value by its width and multiplying that by its position:

colour = (maxVal / width) * xPos

If the scroller is dragged half-way:

colour = (31 / 100) * 50
colour = 15

Regarding ways to represent it - yep, you could use a sprite. I'd just draw a filled rectangle with bevelled edges, though.

#148122 - jay001 - Wed Jan 02, 2008 3:23 pm

thanks alot for that ant! i'll see if this helps me.