Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: maraki_ang3l on Sun 07/06/2009 21:15:12

Title: A little animation
Post by: maraki_ang3l on Sun 07/06/2009 21:15:12
I have my main character entering one room and there  it exists a second character who is walking right left all the time my code is the following :

function room_AfterFadeIn()
{
   cSecond.LockView(13);
   cSecond.Animate(0, 9, eRepeat, eBlock, eForwards);
 
}



function room_RepExec()
{
 cSecond.Walk(43, 449, eBlock, eWalkableAreas);
 cSecond.Walk(959, 449, eBlock, eWalkableAreas);
}

I want my main character to be able to work while the second is walking so I put eBlock,but with the eblock my second character is not walking.

If i put eNoBlock then the second character walks but i have the cursos with the clock...

Any ideas? :)
Title: Re: A little animation
Post by: JpSoft on Sun 07/06/2009 21:49:39
function room_AfterFadeIn()
  {
  cSecond.LockView(13);
  cSecond.Animate(0, 9, eRepeat, eNoBlock, eForwards);
  cSecond.Walk(43, 449, eNoBlock, eWalkableAreas);
  }

function room_RepExec()
  {
  if ((cSecond.x == 959) && (cSecond.y == 449))cSecond.Walk(43, 449, eNoBlock, eWalkableAreas);
  if ((cSecond.x == 43) && (cSecond.y == 449)) cSecond.Walk(959, 449, eNoBlock, eWalkableAreas);
  }


This must work

Jp
Title: Re: A little animation
Post by: Trent R on Sun 07/06/2009 23:03:08
Basically, you can't repeatedly call .Walk() every frame, cause they'll pile up and eventually the character never moves. Jp has changed this so that it only calls a .Walk command if the character is on one of two points.


~Trent
Title: Re: A little animation
Post by: GuyAwesome on Sun 07/06/2009 23:14:29
Or

function room_RepExec()
{
 if (cSecond.Moving == false) {
   cSecond.Walk(43, 449);
   cSecond.AddWaypoint(959, 449);
 }
}


You don't need the eNoBlock, eWalkableAreas parameters for cSecond.Walk, because they're the defaults, as is eForwards for Animate. AddWaypoint ignores walkable areas, so it might not be what you want - in which case go with Jp's version.

Why are you using LockView and starting a repeating animation? Character.Walk will replace that animation with the walking animation (or rather, the appropriate loop from view 36). If you want to keep the animaton running, try using cSecond.Move instead of Walk.
Title: Re: A little animation
Post by: Dualnames on Tue 09/06/2009 00:10:36


int counter;
function room_RepExec()
  {
if ((cSecond.x == 959) && (cSecond.y == 449)) {
if (counter!=80) {//in case you need for the character to wait before walking.
counter++;
}
if (counter==80) {
cSecond.Walk(43, 449);
counter=0;
}
}

}


Don't think it will be mostly helpful but then again it might.

Title: Re: A little animation
Post by: Trent R on Tue 09/06/2009 16:44:27
DN, would you even need the !80 check? I'm thinking that if it is 79 (satisfying !80) then it will be come 80 and then come to the next if and satisfy it. The same would happen without the !80 line, and counter will never be 80 to even check against that line.

[Edit]: Oh wait, that would be useful. You can set counter to a value greater than 80 to disable it. Please forgive my ignorance....


~Trent
Title: Re: A little animation
Post by: GuyAwesome on Tue 09/06/2009 17:06:22
Quote
You can set counter to a value greater than 80 to disable it.

In which case, I'd make it a <80 check, instead of !=80. No functional difference, but 'greater than 80' is also 'not equal to 80', and I don't like the idea of the counter ticking away in the background for no reason. But that could just be me - I don't think it'll interfere with anything if it does keep running, I just ... don't like it.
Title: Re: A little animation
Post by: JpSoft on Tue 09/06/2009 18:32:38
QuoteYou can set counter to a value greater than 80 to disable it.

I did it for the verbcoin system i just designed; if in the moment you press the left button the cursor is over nothing or if you move the mouse before the counter reach 15 is just  matter to assign 16 to the value of counter. The verbcoin GUI never will show until you reset the counter.


if (IsButtonDown(eMouseLeft)) counter++;
else counter=0;
if (GetAtScreen(mouse.X, mouse.Y) == null) counter == 16;
if (OldX != mouse.X) || (OldY != mouse.Y) counter = 16;
if (counter == 15) // Open verb coin
OldX = mouse.X;
OldY = mouse.Y;


Its not the excat code, but i belive it explains very clear how it works

Jp
Title: Re: A little animation
Post by: Trent R on Tue 09/06/2009 18:46:24
Quote from: GuyAwesome on Tue 09/06/2009 17:06:22
In which case, I'd make it a <80 check
Haha, totally right. I made my first reply to the thread, and then came back to it after letting it stew in my head and forgot that is should be <80. But, like you said it would disable it anyways (I also agree that it would bother me too).

~Trent
Title: Re: A little animation
Post by: maraki_ang3l on Tue 09/06/2009 21:49:15
Thanks you all for your replies.I tried them but Ms.GuyAwersome was exactly what i needed. ;D

Thanks guys.
Title: Re: A little animation
Post by: Trent R on Tue 09/06/2009 21:51:49
Glad to help. Besides, it's good for everybody (not just the OP) to discuss other ways of solving problems. Makes you a better scripter.


~Trent
Title: Re: A little animation
Post by: GuyAwesome on Tue 09/06/2009 21:57:39
Indeed, you're welcome. But it's Mr. GuyAwesome, not Ms. ;D
Title: Re: A little animation
Post by: maraki_ang3l on Tue 09/06/2009 22:39:17
Ooops sorry for the mistake  ;)