Hi, can anyone show me some scripts to make a slider?
Thanks,
matthewjose
Offline
Sure! I think the included sliders in Scratch are ugly and I generally avoid using them. You'll need to make two sprites: first, make a 100x3 rectangle, then name it "bar". Next, make a 20x3 rectangle and name it "handle". Move the rotation points on both of them to the far left of each rectangle. Now align them onscreen so "handle" is directly above "bar". Now place the following script on "handle":
//Note: some local variables ("for this sprite only") may be used, and will always begin with "my"
On "handle"
When Flag Clicked:
Forever:
Wait until <<touching mouse pointer?> and <mouse down?>
if <(selected)=0>
set selected to 1
repeat until <not<mouse down?>>
if <<(mouse x)>(x pos of bar)>and<(mouse x)<(x pos of bar)+100>>
set x to (x pos of bar)
set myValue to (x position)-(x pos of bar)
end if
end repeat
end if
end forever
Or, just look at the code I used in my3D Solar System Demo or Cover Flow Slideshow, both of which include very similar sliders. Hope this helps!
Offline
Uhmm......I dont know what 20X3 or stuff like that means, and Scratch's slider are not so ugly.
Last edited by matthewjose (2008-09-17 07:33:07)
Offline
matthewjose wrote:
Uhmm......I dont know what 20X3 or stuff like that means, and Scratch's slider are not so ugly.
I think 20X3 means a costume, 20 pixels wide and 3 pixels high.
Offline
fullmoon wrote:
Sure! I think the included sliders in Scratch are ugly and I generally avoid using them. You'll need to make two sprites: first, make a 100x3 rectangle, then name it "bar". Next, make a 20x3 rectangle and name it "handle". Move the rotation points on both of them to the far left of each rectangle. Now align them onscreen so "handle" is directly above "bar". Now place the following script on "handle":
//Note: some local variables ("for this sprite only") may be used, and will always begin with "my"
On "handle"
When Flag Clicked:
Forever:
Wait until <<touching mouse pointer?> and <mouse down?>
if <(selected)=0>
set selected to 1
repeat until <not<mouse down?>>
if <<(mouse x)>(x pos of bar)>and<(mouse x)<(x pos of bar)+100>>
set x to (x pos of bar)
set myValue to (x position)-(x pos of bar)
end if
end repeat
end if
end foreverOr, just look at the code I used in my3D Solar System Demo or Cover Flow Slideshow, both of which include very similar sliders. Hope this helps!
Wow! That's really useful! Thanks so much!!
Offline
Paddle2See wrote:
matthewjose wrote:
Uhmm......I dont know what 20X3 or stuff like that means, and Scratch's slider are not so ugly.
I think 20X3 means a costume, 20 pixels wide and 3 pixels high.
And.... is 1 pixel = to one pen down in Scratch Draw?
Offline
matthewjose wrote:
Paddle2See wrote:
matthewjose wrote:
Uhmm......I dont know what 20X3 or stuff like that means, and Scratch's slider are not so ugly.
I think 20X3 means a costume, 20 pixels wide and 3 pixels high.
And.... is 1 pixel = to one pen down in Scratch Draw?
Each "Step" in Scratch is one pixel. When you ask Scratch to "Move 10", you are moving 10 pixels. In the Paint Editor, each of the checkerboard squares that you see is 4 pixels wide. In the Costumes tab, under each costume name you will see the size of the costume in pixels. The Scratch Cat costume, in a new Scratch project, is 95x111. Which is 95 pixels wide and 111 pixels high.
Offline
Ive already made one aswell, just got a bug or 2 on the impact of the side of the bar http://scratch.mit.edu/projects/yambanshee/265773
Offline