Character doesn't walk continuously (SOLVED)

Started by proximity, Thu 07/07/2005 03:10:45

Previous topic - Next topic

proximity

  i've used (iskeypressed) command in room's repeatedly_execute section long time ago and it worked well :

// room's repeatedly execute
if (iskeypressed(377)==1)
MoveCharacter(EGO,character[EGO].x+3,character[EGO].y);

My probem is; i wanted to try this command  in room's repeatedly execute again.However, this time, my character didn't walk continuously when i press right arrow key. When i pressed right arrow key, he just kept playing walking animation but didn't move. When i stopped pressing the key, he moved 3 pixels to the right and stopped.

   Why did it not work this time? i used empty game template and version 2.62. Please help! i couldn't find the reason why?
Proximity Entertainment

Kweepa

That might depend on the speed of the player character. Too slow and he won't move a pixel in the frame before you tell him to start moving again.
You could try increasing the player character speed (I think that means reducing the "Speed" number in the character "tab").
Still waiting for Purity of the Surf II

strazer

#2
Are you sure you hadn't used the MoveCharacter command in the room's on_key_press function? The on_key_press function is only called once, when the key is pressed down.

The way your above code in rep_ex works now is that 40 times per second it's checked if the right arrow key is held down and then, the 3-pixel character move is started, !40 times a second!, so it has no chance to actually be executed until the key is released.

You have to check if the movement has already been started before trying to move the character again. Try something like this:

Code: ags

// room script

bool IsMovingRight;

function room_a() {
  // room's repeatedly execute
  //...

  if (IsKeyPressed(377) == true) { // if right arrow key is held down

    if (IsMovingRight != true) { // if NOT moving right already
      cEgo.Walk(cEgo.x + 3, cEgo.y); // start moving EGO 3 pixels to the right
      IsMovingRight = true; // set movement started
    }

  }
  else IsMovingRight = false; // if right arrow key is NOT held down, set movement NOT started

  //...
}


Check out this thread in the Technical Archive on how to do proper multi-directional keyboard control.

proximity

#3
Yes, i am sure i didn't use on_key_press command. When i got wrong result with repeatedly_execute function, i tried also on_key_press function. This time, character didn't move again and also didn't play walking animation.

  This is too weird. i tried this before and it worked. Why is it not working now?

  Wait pls, i will try the script you mentioned and tell you result...

Proximity Entertainment

proximity

strazer, the script you gave me didn't work in verison 2.62.  Do you have any other solutions?
Proximity Entertainment

strazer

Yes, the code is for version 2.7. This is for v2.62:

Code: ags

// room script

int IsMovingRight;

function room_a() {
  // room's repeatedly execute
  //...

  if (IsKeyPressed(377) == 1) { // if right arrow key is held down

    if (IsMovingRight != 1) { // if NOT moving right already
      MoveCharacter(EGO, character[EGO].x + 3, character[EGO].y); // start moving EGO 3 pixels to the right
      IsMovingRight = 1; // set movement started
    }

  }
  else IsMovingRight = 0; // if right arrow key is NOT held down, set movement NOT started

  //...
}

proximity

Proximity Entertainment

SMF spam blocked by CleanTalk