Setting Animation for Actor(Experimenting with State Method)

Non-platform specific questions.

Re: Setting Animation for Actor RENEWED TOPIC

Postby lcl » Wed May 14, 2014 9:39 pm

Turon wrote:Hang on I think I'm getting somewhere I'll report back if there is any trouble.

Okay. Sorry for being so slow. :/
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor RENEWED TOPIC

Postby Turon » Thu May 15, 2014 6:25 pm

Er well I've well bumped into some more trouble again. You see I'm able to display shoot animation when I am still or in the air (from jumping)
but I cannot display a shoot animation when I'm moving left or right, And another pretty bad bug is that I'm no longer able to display a full walk animation
as it only shows one frame.

This is my main code :
Player > Draw Actor > Script Editor
Code: Select all
   char *key=GetKeyState();
   int playerdir=key[KEY_RIGHT]-key[KEY_LEFT];
   int j=key[KEY_x];

switch(playerdir)
{
    case 0: //Non or both
        if(animindex==1 && jump==0)
   {
              ChangeAnimation("Event Actor", "PlayerStillLeft", NO_CHANGE);
        }
        if(animindex==2 && jump==0)
        {
            ChangeAnimation("Event Actor", "PlayerStillRight", NO_CHANGE);
     }
        if(jump==1 && animindex==3)
        {
            ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
        }
        if(jump==1 && animindex==4)
        {
            ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
        }
        if(jump==0 && animindex==5)
        {
            ChangeAnimation("Event Actor", "PlayerStillLeft", NO_CHANGE);
        }
        if(jump==0 && animindex==6)
        {
            ChangeAnimation("Event Actor", "PlayerStillRight", NO_CHANGE);
        }
    break;
 
    case -1: //Left
          Collider.x-=2;
        if(shootdir==1)
        {
            ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
        }
        if(jump!=1)
        {
            ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
   }
        if(jump==1)
        {
            ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
        }
    break;
 
    case 1: //Right
       Collider.x+=2;
       if(shootdir==2)
       {
           ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);
       }
       if(jump!=1)
       {
           ChangeAnimation("Event Actor", "PlayerMoveRight", NO_CHANGE);
       }
       if(jump==1)
       {
           ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
       }
   break;
}
if(Collider.yvelocity<7)
{
    Collider.yvelocity+=.5;
}

And this is my shooting event key "z":
Player > Key Down > Script Editor
Code: Select all
CreateActor("Shot", "Shot", "(none)", "(none)", 0, 0, false);
if(shootdir==1)ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
if(shootdir==2)ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);

If the problem seems a little confusing I've got ma ged here in case we need it.
Attachments
Statik's World.zip
(56.07 KiB) Downloaded 197 times
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor RENEWED TOPIC

Postby skydereign » Fri May 16, 2014 6:05 am

Turon wrote:Player > Draw Actor > Script Editor
Code: Select all
// ...

switch(playerdir)
{
    // ...

    case -1: //Left
          Collider.x-=2;
        if(shootdir==1)
        {
            ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
        }
        if(jump!=1)
        {
            ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
   }
        if(jump==1)
        {
            ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
        }
    break;

    // ...
}

That bit of code is why I really recommend rewriting the player from the ground up using the state method. Notice it doesn't matter if shootdir is true or not, it will always be overridden by the next two if statements. State machines are very logical and it is extremely easy to debug why things aren't working. Giant if nests with tons of variables are not as easy (which is why this topic is so long). You may thing switching will be more work but it would be so much easier and a lot better for you in the long run.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Setting Animation for Actor RENEWED TOPIC

Postby Turon » Fri May 16, 2014 8:19 am

Do you mean this new code is not state method? I thought the code to be much simpler and easier to understand than the last code. Bare in mind the code I displayed there was copied and pasted and the sintax may have been disturbed.
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor RENEWED TOPIC

Postby lcl » Sun May 18, 2014 8:27 pm

Turon wrote:Do you mean this new code is not state method? I thought the code to be much simpler and easier to understand than the last code. Bare in mind the code I displayed there was copied and pasted and the sintax may have been disturbed.

Well, nope, that's not state method. As I told you, you can find a tutorial about state method by searching for "state method" on the Game Editor wiki. Here: http://game-editor.com/State_Method
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor RENEWED TOPIC

Postby skydereign » Mon May 19, 2014 4:38 pm

Turon wrote:I thought the code to be much simpler and easier to understand than the last code. Bare in mind the code I displayed there was copied and pasted and the sintax may have been disturbed.

It is better than what you originally had, but it is a jumbled mess that is still hard to debug. There is no unifying method so it is hard to manage.

Turon wrote:Do you mean this new code is not state method?

As lcl mentions, is not. The state method relies on one major thing which is non-existent in your code. You don't have well defined states. You should declare a single state variable and use that to determine what the player should be doing. This way on any input, or any action that would change the actor's state, you can use a switch statement and tell it exactly what code to run when transitioning from state a to state b (for instance change animation to shoot).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Setting Animation for Actor RENEWED TOPIC

Postby Turon » Tue May 20, 2014 9:20 am

But state method isn't far from what I've got here is it?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor RENEWED TOPIC

Postby lcl » Tue May 20, 2014 2:00 pm

Turon wrote:But state method isn't far from what I've got here is it?

It is. The basic idea is different to what you're doing. In state method you have one variable for telling what the character is doing at any given time.

State method shouldn't be that hard to implement, just follow the instructions on the wiki page I linked you, it has all the information you need to be able to implement it to your game.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Sun May 25, 2014 7:57 pm

Well this has to be state method, I've implemented state method there are still some things to fix but I would like to ask... why does right have to be a even number instead of an odd one? Starting my sprite sheet with "left" makes more sense cause its like a D-pad < > but according to the wiki it has to be like this ><
is it just a matter of preference?
And why are the Animations set to "FORWARD" instead of "NO_CHANGE"?
Attachments
Statik's World (State Method).zip
(28.55 KiB) Downloaded 179 times
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Wed May 28, 2014 9:04 pm

Another little bug is when you jump for example right and press left in midair the player will move left but won't change animation to a jump left.
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Hares » Wed May 28, 2014 10:03 pm

Turon wrote:Another little bug is when you jump for example right and press left in midair the player will move left but won't change animation to a jump left.

That is because on the key down event for the left and right arrow you did not specify any animation change for the states 4 and 5.
If you use this code, then it will work:

Key down - Left
Code: Select all
shootdir=1;
switch(playerdir)
{
    case 0: // if standing right
    ChangeAnimation("Event Actor", "PlayerStillLeft", FORWARD);
    playerdir=1;
    break;
 
    case 1: // if standing left
    ChangeAnimation("Event Actor", "PlayerMoveLeft", FORWARD);
    playerdir=3;
    break;
 
    case 2: // if moving right
    ChangeAnimation("Event Actor", "PlayerMoveLeft", FORWARD);
    playerdir=1;
    break;
 
    case 3: // if moving left
    Collider.x-=3;
    break;

    case 4: // or jumping right
    case 5: // or jumping left
    playerdir=5;
    ChangeAnimation("Event Actor", "PlayerJumpLeft", FORWARD);
    Collider.x-=3;
    break;
}


Key dow - Right
Code: Select all
shootdir=2;
switch(playerdir)
{
   case 0: // if standing right
   ChangeAnimation("Event Actor", "PlayerMoveRight", FORWARD);
   playerdir=2;
   break;
 
   case 1: //if standing left
   ChangeAnimation("Event Actor", "PlayerStillRight", FORWARD);
   playerdir=0;
   break;


   case 3: // if running left
   ChangeAnimation("Event Actor", "PlayerStillLeft", FORWARD);
   playerdir=1;
   break;
 
   case 2: // if moving right
   Collider.x+=3;
   break;

   case 4: // or jumping right
   case 5: // or jumping left
   playerdir=4;
   ChangeAnimation("Event Actor", "PlayerJumpRight", FORWARD);
   Collider.x+=3;
   break;
}
Last edited by Hares on Thu May 29, 2014 3:48 pm, edited 1 time in total.
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby lcl » Wed May 28, 2014 10:21 pm

Turon wrote:why does right have to be a even number instead of an odd one? Starting my sprite sheet with "left" makes more sense cause its like a D-pad < > but according to the wiki it has to be like this ><

I'm not entirely sure about this, but I think that's just because of more easily managing the states and so that the people following the tutorial won't be confused when their system works oppositely to the example. I can't see any other reason for this.
Turon wrote:And why are the Animations set to "FORWARD" instead of "NO_CHANGE"?

That would be because using this method, no animation changing can happen multiple times if you keep a key pressed. The reason for using NO_CHANGE is usually because FORWARD would make the animation always start over, while NO_CHANGE keeps the animpos. With this method, though, that problem doesn't happen because the code works like this:

Key down, right, repeat
Code: Select all
switch(state)
{
    case 0: //let's say this is is standing right state
        ChangeAnimation();
        state = 1; //this is move right state
    break;

    case 1:
        x += 5;
    break;
}

You see, that case 0 is active only for 1 frame when the animation is changed, and then state is set to 1.
If you moved that ChangeAnimation(); to case 1, the normal problem with FORWARD would appear again.

Hares wrote:
Turon wrote:Another little bug is when you jump for example right and press left in midair the player will move left but won't change animation to a jump left.

That is because on the key down event for the left and right arrow you did not specify any animation change for the states 4 and 5.
If you use this code, then it will work:

---

Exactly. Was going to point the same thing out, but you, Hares, were faster :D Great work finding the bug, it's often not that easy to see what is wrong with other people's codes.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Thu May 29, 2014 2:08 pm

Hares I tried your code but it has some bugs for example if I jump left and press right in mid air (falling down) it will change animation to standing right animation.
And also if you press for example "left" and jump and while your jumping (or falling) you can jump in mid air. Maybe its because I've change the order of animations?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Hares » Thu May 29, 2014 3:52 pm

Turon wrote:Hares I tried your code but it has some bugs for example if I jump left and press right in mid air (falling down) it will change animation to standing right animation.
And also if you press for example "left" and jump and while your jumping (or falling) you can jump in mid air. Maybe its because I've change the order of animations?

No, it has nothing to do with the order of the animations.
In the code I made a mistake. Howerver I edited my previous post so it should be alright now. Try again with the new code in the previous post ...

The mistake was that I set the playerdir to 2 or 3 for the left or right jump, but it should be 4 or 5.
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Thu May 29, 2014 4:28 pm

Thank you Hares the code works as should :) .
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron