Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FortressCaulfield on Wed 05/06/2024 13:31:42

Title: Why is changeview so unreliable?
Post by: FortressCaulfield on Wed 05/06/2024 13:31:42
This function works:

function OvaSquat(int x, int y) // pass the x,y of where you want her hand to be
{
  if (cOva.x < (x - 40)) cOva.Walk((x-40), y, eBlock, eWalkableAreas);
  else cOva.Walk((x+40), y, eBlock, eWalkableAreas);
 
  cOva.ChangeView(18);
  switch (cOva.Loop)
  {
    case 0: cOva.Animate(4, 4, eOnce, eBlock, eForwards); break;
    case 1: cOva.Animate(5, 4, eOnce, eBlock, eForwards); break;
    case 2: cOva.Animate(4, 4, eOnce, eBlock, eForwards); break;
    default: cOva.Animate(5, 4, eOnce, eBlock, eForwards); break;
  }
}

This function DOESN'T work, and tries to play a loop from her walk animation, despite the changeview call being literally right there in the same place.

function OvaKeycard(int x,  int y) //pass the bottom center of door
{
  if (cOva.x < (x - 60)) cOva.Walk((x-60), (y+25), eBlock, eWalkableAreas);
  else cOva.Walk((x+60), (y+25), eBlock, eWalkableAreas);
 
  cOva.ChangeView(18);
  switch (cOva.Loop)
  {
    case 0: cOva.Animate(6, 4, eOnce, eBlock, eForwards); break;
    case 1: cOva.Animate(6, 4, eOnce, eBlock, eForwards); break;
    case 2: cOva.Animate(7, 4, eOnce, eBlock, eForwards); break;
    default: cOva.Animate(7, 4, eOnce, eBlock, eForwards); break;
  } 
}

This isn't the only time this has come up. What's wrong with this function?
Title: Re: Why is changeview so unreliable?
Post by: Crimson Wizard on Wed 05/06/2024 13:43:36
With Animate function you are supposed to call LockView before Animate and UnlockView after. This is explained in the relevant article from the manual:
https://adventuregamestudio.github.io/ags-manual/Character.html#characteranimate

ChangeView is not meant for calling Animate, it's meant for setting current standing/walking view that engine animates automatically as character walks around. This is also noted in its article:
https://adventuregamestudio.github.io/ags-manual/Character.html#characterchangeview

To be honest, I cannot tell why exactly it switches to a regular walking view in your second function. Maybe there's another factor affecting this situation. I'd would need to have a minimal test case where the problem reproduces to diagnose this.
In any case, using LockView/UnlockView pair is supposed to ensure that Animate plays correctly.
Title: Re: Why is changeview so unreliable?
Post by: FortressCaulfield on Wed 05/06/2024 17:44:18
Thanks for the info. I need to read the manual more I suppose.