Slider Tutorial

Learn how to make certain types of games and use gameEditor.

Slider Tutorial

Postby Rebenely » Mon Jul 06, 2015 3:42 am

This will be my first tutorial so if there's anything wrong, just say it and I'll do something about it.

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
These variables determine the parameters of our slider.

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.
Attachments
slider.zip
Contains .ged file and data files.
(40.75 KiB) Downloaded 201 times
User avatar
Rebenely
 
Posts: 16
Joined: Fri Apr 05, 2013 1:13 pm
Score: 1 Give a positive score

Re: Slider Tutorial

Postby Rebenely » Mon Jul 06, 2015 3:44 am

Screenshot
Attachments
screens.png
User avatar
Rebenely
 
Posts: 16
Joined: Fri Apr 05, 2013 1:13 pm
Score: 1 Give a positive score

Re: Slider Tutorial

Postby DeltaLeeds » Tue Jul 28, 2015 7:34 am

Nicely done Rebenely! This could help volume and other stuff that requires sliders as well! :D
+1 for the tutorial. :)
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest