Page 1 of 1

Tutorial: Make your onscreen buttons!

PostPosted: Mon Oct 18, 2010 1:16 pm
by lcl
Hello! :D

I decided to make onscreen buttons tutorial 'cause I found very good way to do it.
This post will also include little example of how to use them. :D

First go to global code and type this:
Code: Select all
#define NOTHING 0
#define RIGHT 1
#define LEFT 2
#define UP 3
#define DOWN 4
#define ATTACK 5
//you can name those what ever you want, this is just example... :)


Then create actor called buttons or something.. :D
Make as many clones of it as you want. Then give the clones the animations that you want them to have.

Then goto player draw actor script and create two variables, jump and move. Make them as global, integer.
Then write in to players draw actor script:
Code: Select all
yvelocity += .5;

switch(move)
{
    case RIGHT:
    x += 5;
    ChangeAnimation("Event Actor", "WalkRight", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;

    case LEFT:
    x -= 5;
    ChangeAnimation("Event Actor", "Walkleft", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;

    case JUMP:
    if (jump == 1)
    {
        yvelocity = - 10;
        jump = 0;
    }
    break;
}


Player - collision any side of ground repeat: yes - script editor:
Code: Select all
//Put here the physical response
jump = 1;


And to buttons mouse button down:
Code: Select all
switch(cloneindex)
{
    case 0:
    move = LEFT;
    break;

    case 1:
    move = RIGHT;
    break;

    case 3:
    move = JUMP;
    break;

    //you can add any amount of moves here and then describe them in players draw actor code.
}


buttons mouse button up:
Code: Select all
move = NOTHING;

if (animindex == put here the animindex of moving left)
{
    changeanimation(... stopLeft);
}

if (animindex == put here the animindex of moving right)
{
    changeanimation(... stopRight);
}


Tell me what you think!
And if you don't understand something, ask! :D

Re: Tutorial: Make your onscreen buttons!

PostPosted: Tue Oct 19, 2010 8:30 pm
by Hblade
Very helpfull, thanks! :D

Re: Tutorial: Make your onscreen buttons!

PostPosted: Tue Oct 19, 2010 8:37 pm
by lcl
:D Glad you like it. (I know, that's your own comment, but I like it so much. :lol:)

Re: Tutorial: Make your onscreen buttons!

PostPosted: Tue Oct 19, 2010 9:06 pm
by Hblade
Yeah, I forgot all about the #define lol :P thanks for reminding me xD

Re: Tutorial: Make your onscreen buttons!

PostPosted: Thu Oct 21, 2010 9:59 am
by SirAz
Hmm. I'm using variables for iphone movement at the moment, but it doesn't always work so well. Using states as you have seems a much more effecient way of doing things. This was really helpful, thanks!

Re: Tutorial: Make your onscreen buttons!

PostPosted: Thu Oct 21, 2010 11:10 am
by lcl
SirAz wrote:Hmm. I'm using variables for iphone movement at the moment, but it doesn't always work so well. Using states as you have seems a much more effecient way of doing things. This was really helpful, thanks!


That's nice to hear. :)

Re: Tutorial: Make your onscreen buttons!

PostPosted: Sat Oct 22, 2011 4:28 pm
by Bee-Ant
lcl wrote:
Code: Select all
yvelocity += .5;
switch(move)
{
    ***case: RIGHT:***
    x += 5;
    ChangeAnimation("Event Actor", "WalkRight", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;
   
    case LEFT:
    x -= 5;
    ChangeAnimation("Event Actor", "***Walklefht***", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;

    //etc
}

Be careful...mistype on code will cause an error ;)
I guess here the correct code:
Code: Select all
yvelocity += .5;
switch(move)
{
    case RIGHT:
    x += 5;
    ChangeAnimation("Event Actor", "WalkRight", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;
   
    case LEFT:
    x -= 5;
    ChangeAnimation("Event Actor", "WalkLeft", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;

    //etc
}

:)

Re: Tutorial: Make your onscreen buttons!

PostPosted: Sat Oct 22, 2011 5:20 pm
by SuperSonic
Very nice tutorial lcl. +1 man :D

Re: Tutorial: Make your onscreen buttons!

PostPosted: Sat Oct 22, 2011 8:18 pm
by lcl
SuperSonic wrote:Very nice tutorial lcl. +1 man :D

Thanks! :)
Bee-Ant wrote:
lcl wrote:
Code: Select all
yvelocity += .5;
switch(move)
{
    ***case: RIGHT:***
    x += 5;
    ChangeAnimation("Event Actor", "WalkRight", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;
   
    case LEFT:
    x -= 5;
    ChangeAnimation("Event Actor", "***Walklefht***", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;

    //etc
}

Be careful...mistype on code will cause an error ;)
I guess here the correct code:
Code: Select all
yvelocity += .5;
switch(move)
{
    case RIGHT:
    x += 5;
    ChangeAnimation("Event Actor", "WalkRight", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;
   
    case LEFT:
    x -= 5;
    ChangeAnimation("Event Actor", "WalkLeft", NO_CHANGE); //Make sure to choose no_change instead of forward
    break;

    //etc
}

:)

Oh yeah, thanks for pointing those, have to correct them. :D