This tutorial is for simple sliders.
First, you have to create an actor whose events will be inherited by the sliders that we will make. For this tutorial, we'll call it slidercreator
- Code: Select all
Add Actor -> Name: slidercreator
type: Normal
This actor will just let other actors inherit mouse button events so we don't have to do that every time we create a slider.
- Code: Select all
Add Event -> Mouse Button Down -> Left/Disable Drag -> Follow Mouse (Event Actor, x axis)
- Code: Select all
Add Event -> Mouse Button UP -> Left -> Follow Mouse (Event Actor,none)
Now we need to create actor variables
So go to add these variables, all Integer and Actor variables
- xstore
to
from
length
Now go to global code and add this:
- Code: Select all
void createslider(int xpos, int fromx, int tox, int lengthx){
xstore = xpos;
from = fromx;
to = tox-from;
length = lengthx;
}
For this tutorial, we'll name it slide. This function will tell the game that the actor is a slider.
Now, we'll create the actual slider. Create a new actor, for this tutorial we'll be changing the r,g,b value of another actor.
So we will create four actors named: red,green,blue and the target which we will change r,g,b values.
For the red,green,blue actors, we will let it inherit events from slidercreator.
And on each, add an create actor event, click script editor then type this
- Code: Select all
createslider(x,0,255,375);
the x in this function (first parameter) will store whatever the current x of your actor, so it won't go left/lower of that.
the 0 (second parameter) will be the least value that our slider can give.
the 255 (third parameter) will be the greatest value that our slider can give.
the 375 (third parameter) will be the length of the slider. I chose 375 so it will be exact to the sliderbg actor (just a graphical interface, see demo)
And on each of red,blue,green, add these on their draw actors -> script editor:
- Code: Select all
if( ((x+from) - xstore )>length){
x = xstore+length;
} else if (((x+from)-xstore)<=0){
x = xstore;
}
It limits the movement of the slider to the length given in the createslider function.
Now this will be the one that will give the actual value.
For red since we will be changing target.r, we'll use this:
Draw Actor -> Script Editor
- Code: Select all
target.r = ((((x-xstore)/length)) * (to))+ from;
For green:
Draw Actor -> Script Editor
- Code: Select all
target.g = ((((x-xstore)/length)) * (to))+ from;
For blue:
Draw Actor -> Script Editor
- Code: Select all
target.b = ((((x-xstore)/length)) * (to))+ from;
You can add the optional indicator by just adding another actor for it.
Here's the .ged file if you can't make it work.