Page 1 of 4

actor n background

PostPosted: Tue Jun 05, 2012 11:38 am
by dzuncoi
hello guys, im just use game editor for 3 days, i want to ask u some questions
i create an actor, it can move by left n right key, but i dunno how to make background follow the actor :(
i try to use wire frame region actor and add collision event to them but still not work, i dunno why :( anyone can help me clearly ?

Re: actor n background

PostPosted: Tue Jun 05, 2012 4:12 pm
by phyzix5761
If you just want a basic follow you have to parent the background to your actor. Go into the actor control menu for the background and change parent to the actor you want the background to follow.

Re: actor n background

PostPosted: Tue Jun 05, 2012 4:32 pm
by skydereign
phyzix5761 wrote:If you just want a basic follow you have to parent the background to your actor. Go into the actor control menu for the background and change parent to the actor you want the background to follow.

That won't work, due to the child actor always being on a higher zdepth than its parent. Most likely though you want it to just follow the view. Depending on how you are doing view movement (if your view is parented to the player) you need to do this.
background -> Draw Actor -> Script Editor
Code: Select all
xscreen=view.width/2; // this will center the background actor to the view
yscreen=view.height/2;


Or if you aren't parenting the player to the view, you can just parent the background to the view. If though your background appears in front of the player, either raise the player's zdepth, or better yet lower the view's zdepth.

Re: actor n background

PostPosted: Wed Jun 06, 2012 6:02 am
by dzuncoi
arrrrrrrrr thank u guy, i got it :D just need to parent 2,3 actor, so simple :D
can i ask some more questions :?
anyone help me explain these code plz

Code: Select all
switch(STATE)
{
    case 0:
    break;

    case 1:
    break;
 
    case 2:
    break;
 
    case 3:
    break;
 
    case 4:
    if(yvelocity>0)
    {
 //       ChangeAnimation("Event Actor", "r_fall", NO_CHANGE);
 //       STATE=6;
    }
    break;
 
    case 5:
    if(yvelocity>0)
    {
 //       ChangeAnimation("Event Actor", "l_fall", NO_CHANGE);
 //       STATE=7;
    }
    break;
 
    case 6:
    break;
 
    case 7:
    break;
 
    // turning animation
 
}
if(yvelocity>3)
{
    if(STATE%2==1)
    {
        ChangeAnimation("Event Actor", "l_fall", NO_CHANGE);
        STATE=7;
    }
    else
    {
        ChangeAnimation("Event Actor", "r_fall", NO_CHANGE);
        STATE=6;
    }
}
yvelocity++;


explain me what it's for n meaning of the commands clearly, thank very much :)

Re: actor n background

PostPosted: Wed Jun 06, 2012 6:49 am
by happyjustbecause
dzuncoi wrote:arrrrrrrrr thank u guy, i got it :D just need to parent 2,3 actor, so simple :D
can i ask some more questions :?
anyone help me explain these code plz

Code: Select all
switch(STATE)
{
    case 0:
    break;

    case 1:
    break;
 
    case 2:
    break;
 
    case 3:
    break;
 
    case 4:
    if(yvelocity>0)
    {
 //       ChangeAnimation("Event Actor", "r_fall", NO_CHANGE);
 //       STATE=6;
    }
    break;
 
    case 5:
    if(yvelocity>0)
    {
 //       ChangeAnimation("Event Actor", "l_fall", NO_CHANGE);
 //       STATE=7;
    }
    break;
 
    case 6:
    break;
 
    case 7:
    break;
 
    // turning animation
 
}
if(yvelocity>3)
{
    if(STATE%2==1)
    {
        ChangeAnimation("Event Actor", "l_fall", NO_CHANGE);
        STATE=7;
    }
    else
    {
        ChangeAnimation("Event Actor", "r_fall", NO_CHANGE);
        STATE=6;
    }
}
yvelocity++;


explain me what it's for n meaning of the commands clearly, thank very much :)


Well, I'll attempt to explain the code for you, as I learned this method. So...

Code: Select all
switch(STATE)


This means that you are switching a variable called STATE. This variable can be used for anything, but in this case it is used for switching animations and preventing moonwalking.

Code: Select all
case 0:
break;

case 1:
break;


These are the conditions for when state is equal to 0 or 1. It is basically saying if state is equal to 0 (or whatever # it may be), run this code until a break. So if you want to set the color value red to 0 when in case 0, and you want to switch to state equaling 1 you would put:

Code: Select all
case 0: // switch r value to 0
r=0;
state=1;
break;


generally case 0 and case 1 are the standing right and left states. So the state method can be used for changing animations in this way:

Code: Select all
case 0: // Right Stand to Right Run
ChangeAnimation("Event Actor", "Right Run", FORWARD);
state=2;
break;

case 1: // Left Stand to Left Run
ChangeAnimation("Event Actor", "Left Run", FORWARD);
state=3;
break;


Code: Select all
    case 4:
    if(yvelocity>0)
    {
 //       ChangeAnimation("Event Actor", "r_fall", NO_CHANGE);
 //       STATE=6;
    }
    break;
 
    case 5:
    if(yvelocity>0)
    {
 //       ChangeAnimation("Event Actor", "l_fall", NO_CHANGE);
 //       STATE=7;
    }
    break;


cases 4 and 5 would be the falling animations switching. And the animations and states only switch if there is any positive yvelocity.

Code: Select all
if(yvelocity>3)
{
    if(STATE%2==1)
    {
        ChangeAnimation("Event Actor", "l_fall", NO_CHANGE);
        STATE=7;
    }
    else
    {
        ChangeAnimation("Event Actor", "r_fall", NO_CHANGE);
        STATE=6;
    }
}
yvelocity++;


The code above again only triggers if there is yvelocity, except this time if the yvelocity is greater than 3. The line if(STATE%2==1) is making sure if the state is essentially even or odd. In the state method, generally even numbers are made up of animations facing right, odd numbers are made up of animations facing left. And along with the animations changing, the value of state changes.

And the code on the bottom "yvelocity++;" isn't related to the state method, but it merely means to have yvelocity increase,

Re: actor n background

PostPosted: Wed Jun 06, 2012 9:02 am
by dzuncoi
yeah, i need time to understand all these things, still have some troubles :) thank u very much :D

ah hey happyjustbecause, in the tutorial, in the "draw actor" event they have 1 code ("state" included) and in "keydown" event, they also have some codes that include "state", i wonder these "state" have any connections ? i think yes, right ? :?

Re: actor n background

PostPosted: Wed Jun 06, 2012 4:22 pm
by skydereign
Yes, those are the same variable. The idea of that variable is very important, and pretty simple. The state variable just holds a number that represents something the player can do. For instance, 0 means the player is standing right, 1 means the player is standing left, 2 means the player is running right, and so on.

The switch statement allows you to tell the actor how to react depending on what the actor's current state is. So in a keydown right event, you can tell the actor exactly what you want it to do, depending on what is currently doing. I assume you were looking at my demo of the state method, in which case you might want to read this. http://game-editor.com/State_Method

Re: actor n background

PostPosted: Thu Jun 07, 2012 9:34 am
by dzuncoi
yeah, i now understand this method, really simple :D thank u all :D

Re: actor n background

PostPosted: Thu Jun 07, 2012 2:11 pm
by dzuncoi
hey guy, i want to ask 1 question, i creat a player n a ground, i also add physical response for the player like this
PhysicalRespons(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.00, 1.00, 0.00, 0.00);
but it doesn't work, there r some positions that make my player fall through the ground, anyone can help me fix it :(

Re: actor n background

PostPosted: Thu Jun 07, 2012 3:36 pm
by skydereign
Is the collision event set to repeat? If not, then a constant collision will cause the actor to fall through. Also you need to have the collision event specify all direction or create separate collisions for the different sides.

Re: actor n background

PostPosted: Thu Jun 07, 2012 4:10 pm
by dzuncoi
aaaaaaaaaaaaaaa thank u guy, i added collision for the left n right side n it's ok now :D
i think it will take me lots of time to use this program effectively :D

Re: actor n background

PostPosted: Thu Jun 07, 2012 5:58 pm
by dzuncoi
i have problem again :( how can we differentiate between 4 sides of an actor ? cos i want the player die when he collide with left or right side of an monster n destroy the monster when he collide on the top, but something went wrong, sometimes the player hit the snake head n destroy the snake :( or sometimes the player hit on the top of the snake but he n the snake die together :evil: just 50% right and 50% wrong, s.o help me plz :(

Re: actor n background

PostPosted: Thu Jun 07, 2012 6:16 pm
by skydereign
Well normally you use the top side/bottom side/left or right side collisions for this. But the problem is that usually most collisions trigger at least two. You can limit this by using bounding box actors so that the collisions are clean rectangles (making it easier for gE to distinguish the side of collisions).

Re: actor n background

PostPosted: Fri Jun 08, 2012 5:46 am
by dzuncoi
can u show me more clearly :( i got the idea but dunno how to do it

ar, i did it :D

Re: actor n background

PostPosted: Fri Jun 08, 2012 7:48 am
by dzuncoi
hey guy, when u make a game n need some animation, u creat them by urselves or u search on internet ? cos i got some animation from internet but it's not as i expected :( but i dont think i can creat animation myself at that time :(