Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How to create a slider bar?

Author
Message
Merripen
4
Years of Service
User Offline
Joined: 27th Feb 2015
Location:
Posted: 1st Mar 2015 05:57
I am trying to create a slider bar for an app that can select a number between 1 and 100. I also want to include a text box that I can enter in a number that will also move the slider bar and moving the slider also changes the number value in the text box.

I have found some older code examples from dark basic, but still don't know enough to make it work in AGK2.

All I have achieved so far that worked is creating the images/sprites

[/code]
//set display
SetWindowTitle("Slider test")
SetWindowSize( 1024, 720, 0 )
SetDisplayAspect(1024/720.0)
//load resources
slidebar = loadimage("scrollbar.bmp")
scrollbutton = loadimage("ScrollButton.bmp")

//create sprites

slidebar_spr = CreateSprite(slidebar)
setspritesize(slidebar_spr,80,1)
SetSpritePosition(slidebar_spr,10,81)


scrollbutton_spr = CreateSprite(scrollbutton)
setspritesize(scrollbutton,1,3)
SetSpritePosition(scrollbutton,15,80)

//display sprites

SetSpriteVisible(slidebar_spr,1)
SetSpriteVisible(scrollbutton_spr,1)
[code]

Any help would be greatly appreciated!
Conjured Entertainment
AGK Developer
14
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 2nd Mar 2015 00:50 Edited at: 2nd Mar 2015 01:28
I don't do my sprite creation like you guys... I load the image in as I assign it a number...

CreateSprite(1, loadimage("scrollbar.bmp"))

... so the method you guys use confuses me.

However,unless I am mistaken, you are using the loadimage() var as the sprite id....

setspritesize(scrollbutton,1,3)
SetSpritePosition(scrollbutton,15,80)

should be ...

setspritesize(scrollbutton_spr,1,3)
SetSpritePosition(scrollbutton_spr,15,80)

Once you fix that, then all you need is a loop to sync() and get the input...

An easy way for input is a virtual button for your button sprite.
Just assign the up and down images for the button with that image you are using.
Then a...

if getvirtualbuttonpressed(1) = 1
  //reposition it to the getpointerX()
  SetVirtualButtonPosition(1, getpointerX(), 80)
endif

... could slide it.
You could put a couple more if statement to set a valid range of values for that getpointerX() before you use if you add a variable to hold it...


That just slides the button. You still have to add the function it does, or value it changes, at the spot where the reset of position is done.


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Mar 2015 23:13
I'll leave the sprite graphics up to you, but here's a working example using built-in graphics.




"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Merripen
4
Years of Service
User Offline
Joined: 27th Feb 2015
Location:
Posted: 4th Mar 2015 05:23
Thanks a bunch for the help, I have successfully created a few different scrollbars, using sprite graphics and the built in graphics. I will update this thread once i have fine tuned my code.

Login to post a reply

Server time is: 2019-10-17 04:40:29
Your offset time is: 2019-10-17 04:40:29