Page 1 of 1

On-Screen Control Tutorial

PostPosted: Thu Feb 16, 2012 4:23 am
by Bee-Ant
Hi everyone.
Since I got so many request about this stuff, so here I make it.

ON-SCREEN CONTROL FOR PLATFORMER GAME

First of all, create the needed actors:
1. ButtonLeft
2. ButtonRight
3. Button Jump
Don't forget to set those button's ZDepth to the highest value. And the transparency to be about 30% (optional)
Image
4. Platform
5. Background
6. Player
For easier animation management for the player, I named his animations with format "Name-Action-Direction" as follows:
- "PlayerStopLeft"
- "PlayerStopRight"
- "PlayerRunLeft"
- "PlayerRunRight"
- "PlayerJumpLeft"
- "PlayerJumpRight"
Image


Now, let's move to the coding step:

1. Prepare the needed variables on Global code
Code: Select all
int Action; //0: Stop, 1: Run
int Direction; //-1: Left, 0: None, 1: Right
int Jump; //0: On the ground, 1: Jumping

char PlayerAction[3][16]={"Stop","Run"};
char PlayerDirection[4][16]={"Left","None","Right"};


2. Set the Player basic code:
- Player > Collision > Any Side; Repeat: Yes > Platform:
Code: Select all
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 0.000000);

- Player > Collision > Top Side; Repeat: Yes > Platform:
Code: Select all
Jump=0; //Grounding

- Player > Create Actor:
Code: Select all
//Initial value
Action=0; //Stop
Direction=1; //Facing Right

- Player > Draw Actor:
Code: Select all
char tmp[32];

yvelocity++; //gravity effect
x+=Action*Direction*5; //5 is the walking speed

if(Jump==0) //if on the ground
{
    //Get the player animation name based on it's condition (Name+Action+Direction)
    //and store it to 'tmp' variable
    sprintf(tmp,"Briver%s%s",PlayerAction[Action],PlayerDirection[Direction+1]);
    //change the animation as the stored value
    ChangeAnimation("Event Actor", tmp, NO_CHANGE);
}
if(Jump==1) //if jumping
{
    sprintf(tmp,"BriverJump%s",PlayerDirection[Direction+1]);
    ChangeAnimation("Event Actor", tmp, NO_CHANGE);
}


3. Now, setup the control. This is the key feature. While in normal control (without using on-screen key) you set the control mostly in "Player > Key Down" and "Player > Key Up"... in on-screen control, we set the player control in "Button > Mouse Click" and "Button > Mouse Down".
- ButtonLeft > Mouse Button Down > (Left Click):
Code: Select all
Action=1; //Walk
Direction=-1; //Facing Left

- ButtonLeft > Mouse Button Up > (Left Click):
Code: Select all
Action=0; //Stop

- ButtonRight > Mouse Button Down > (Left Click):
Code: Select all
Action=1; //Walk
Direction=1; //Facing Right

- ButtonRight > Mouse Button Up > (Left Click):
Code: Select all
Action=0; //Stop

- ButtonJump > Mouse Button Down > (Left Click):
Code: Select all
if(Jump==0) //if on the ground
{
    Player.yvelocity=-15;
    Jump=1; //Jump
}


That is all the basic.
You can add more tweaks you want.
Let me know if you have any question.
Good luck :D

Image

Here's the full demo: http://dl.dropbox.com/u/3997355/Demo/On ... ontrol.zip

Re: On-Screen Control Tutorial

PostPosted: Thu Feb 16, 2012 7:31 am
by Fuzzy
Bee-Ant wrote:Let me know if you have any question.


Yeah, I have a few questions.

What's with your face? Why is it like that? :P :P

Re: On-Screen Control Tutorial

PostPosted: Thu Feb 16, 2012 8:30 am
by Bee-Ant
Fuzzy wrote:What's with your face? Why is it like that?

What's with my face?handsome???cute???
Oh, I don't know whether this is a miracle or curse...
Please don't mention my handsomeness anymore, you made me shy :oops:

Re: On-Screen Control Tutorial

PostPosted: Thu Feb 16, 2012 11:22 am
by Fuzzy
Bee-Ant wrote:
Fuzzy wrote:What's with your face? Why is it like that?

What's with my face?handsome???cute???
Oh, I don't know whether this is a miracle or curse...
Please don't mention my handsomeness anymore, you made me shy :oops:


Haha! Nice reply!

Re: On-Screen Control Tutorial

PostPosted: Thu Feb 16, 2012 1:01 pm
by DST
*pukes*

Re: On-Screen Control Tutorial

PostPosted: Thu Feb 16, 2012 4:35 pm
by SuperSonic
I love the sarcasm around here :P

Re: On-Screen Control Tutorial

PostPosted: Thu Oct 03, 2013 8:09 pm
by Behdadsoft
can use this method for iPhone games?

Re: On-Screen Control Tutorial

PostPosted: Thu Oct 03, 2013 11:35 pm
by JaroodaGames
Behdadsoft wrote:can use this method for iPhone games?

Pretty sure that's what this tutorial is made for.

Re: On-Screen Control Tutorial

PostPosted: Fri Oct 04, 2013 8:26 am
by Behdadsoft
Pretty sure that's what this tutorial is made for.


Thanks

+1 :D