Detecting the current loop.. not working how it should(SOLVED)

Started by budsmoka, Thu 26/08/2010 04:52:17

Previous topic - Next topic

budsmoka

Okay so basicly Im putting together a mortal kombat style fighter(snes version) Where you only move two directions. Each direction is on a different loop.

I got a second view with a couple of punching animations on it.

execute repeatedly looks something like this. (i know some of the syntax doesnt make sense, but its just to give you an idea since its a very short script you shouldnt have trouble.

If(KeyPressed == true)
{

  if(cCharacter.Loop == 1)  #Should be the loop which faces left.
{
    cCharacter.LockView(2);
   cCharacter.Animate(0,4,norepeat Etc Etc

}

 if(cCharacter.Loop == 2)  #Should be the loop which faces right.
{
    cCharacter.LockView(2);
   cCharacter.Animate(1,4,norepeat Etc Etc

}
}

Okay its something extremely similar, except with an additional if to tell when the animating is done, and to switch back to the normal view.

However for some reason it always comes back as loop 1(the facing left loop) Even when the loop that is really being used is 2 (The right loop)  So as you can see something isnt going as planned.

Any help would be greatly appreciated, and if this is too sloppy or something Im sure I can comeup with the exact codeI'm using, its just on another computer right now.

Thanks in advance.



Gilbert

Hmmm. Where are the codes that you use to set/change the loop of the character?

budsmoka

Im not sure I completely understand the question.

The loop of the character im trying to detect is whichever loops its currently on like if the character is currently facing towards the right of the screen, its loop 1, if he is facing left all the left walking animations are set for loop 2.

There are no up or down movements.

all Im trying to do is find which direction is currently being faced it has to be either 1 or 2 because those are the only loops in the normal view.

I have noticed something very odd.

if i change these around

   if(cCharacter.Loop == 2)  #Should be the loop which faces left.

  if(cCharacter.Loop == 1)  #Should be the loop which faces right.

it works but when the punch animations play the go in the opposite direction that they are supposed to, so i tried changing the

cCharacter.Animate(1,4,norepeat Etc Etc bits around too to match the right directions, but for some reason when i change those around too it quits working again.   IM LOST


budsmoka

My apologies for the double post. Here is the exact code from the game.

function repeatedly_execute_always()
{
  if(player.Animating == false)
  {
    if(player.View == 2)
    {
      player.LockView(1);
    }
   
  }
 
  if(IsKeyPressed(90) == true)
  {
   
   
    if(player.Loop == 1)
    {
   player.LockView(2);
   player.Animate(0, 4, eOnce, eNoBlock);
    }
   
   if(player.Loop == 2)
    {
   player.LockView(2);
   player.Animate(1, 4, eOnce, eNoBlock);
    }
  }
   
   
}

What i was talking about earlier is that if I change the player.loop == 1, and player.loop == 2 around then it works. but obviously its set to play the punch animation in the wrong direction if i change them..

So I tried changing the  - player.Animate(1, 4, eOnce, eNoBlock); parts around to fit the right animation in the right direction however when I do that it quits working again.

Gilbert

#4
I reread your codes and I know what's the problem now.

The problem is this, when your character is facing right (loop 2), you animate him using loop 1. So, as the codes are in repeatedly_execute(), in the next game frame, the if (playing.Loop==1) part would be run again, i.e. forcing the animation to face left (as when you press a key the duration would quite possibly be longer than a game frame, so the IsKeyPressed() part will still be taken in the next frame).

There're many ways to fix this, one suggestion is to use some variables to keep track of whether a key was pressed in the last game frame and don't do any more thing if the same key is still being kept pressed in the following frames. A simpler solution is, however, do not use loop 1 and loop 2 in those action animations.

budsmoka

YAY!!!

It is fixed.. I completely forgot to think about the fact that it was being repeatedly executed.  It works exactly how I intended now.

Thank you.

SMF spam blocked by CleanTalk