MODULE: BACKGROUND SPEECH (with animation&sound!) v1.1.0 (for AGS 3.2+)

Started by Electroshokker, Sat 11/10/2008 10:19:51

Previous topic - Next topic

Snarky

Quote from: monkey0506 on Thu 04/07/2013 13:26:11
That's literally all there is to it.

If anyone's looking to implement this, that's not quite true. You have to actually store the overlay in the array (or the animation will never end), and null it out when you stop the animation (or the character will afterwards refuse to perform any other animations, including walking). This should do it:

Code: ags
// Script.ash

import Overlay* SayInBackground(this Character*, String text);

// Script.asc

Overlay *backgroundSpeech[]; // pointer to any character's background speech overlay

function game_start()
{
  backgroundSpeech = new Overlay[Game.CharacterCount]; // initialize array of pointers
}

function repeatedly_execute()
{
  int i = 0;
  while (i < Game.CharacterCount) // iterate all pointers checking for ended background speech
  {
    if ((backgroundSpeech[i] != null) && (!backgroundSpeech[i].Valid))
    {
      character[i].UnlockView(); // unlock character from speech view when done talking
      backgroundSpeech[i] = null;
    }
    i++;
  }
}

Overlay* SayInBackground(this Character*, String text)
{
  Overlay *o = this.SayBackground(text);
  if ((o != null) && (this.SpeechView > 0))
  {
    backgroundSpeech[this.ID] = o;
    this.LockView(this.SpeechView);
    this.Animate(this.Loop, this.AnimationSpeed, eRepeat, eNoBlock, eForwards);
  }
}

SMF spam blocked by CleanTalk