Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - bx83

#622
Here's my code, still doesn't work, and get's the dark blue in the second picture:

Code: ags

function getRVG(int color) {
  int c = color;
  if (c == -1) c = 63519;
  int cc = c / 2048;
  int cr , cg, cb;
  cr = cc * 8;
  c = c - (cc * 2048);
  cc = c / 64;
  cg = (cc * 8);
  c = c - (cc * 64);
  if (cg > 0) {
    cg += 4;
    c -= 32;
  }
  cb = c * 8;
  if (cb < 0) {
    if (cg > 4) cg -= 4;
    cb = 256 + cb;
  }
  Phylactere_col_r = ((cr * phylactere.transparency) + (phylactere.transparency_red * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_r > 255) Phylactere_col_r = 255;
  if (Phylactere_col_r < 8) Phylactere_col_r = 8;
  Phylactere_col_g = ((cg * phylactere.transparency) + (phylactere.transparency_green * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_g > 255) Phylactere_col_g = 255;
  if (Phylactere_col_g < 8) Phylactere_col_g = 8;
  Phylactere_col_b = ((cb * phylactere.transparency) + (phylactere.transparency_blue * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_b > 255) Phylactere_col_b = 255;
  if (Phylactere_col_b < 8) Phylactere_col_b = 8;
}


Not sure about a GUI or Overlay... How would I....?
#623
It doesn't entirely work, just changes the blue to a darker tone. Also doesn't make a difference if I replace line 4 with '16' or lines 7 and 10 with '8' or '16'.

Code: ags

  Phylactere_col_r = ((cr * phylactere.transparency) + (phylactere.transparency_red * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_r > 255) Phylactere_col_r = 255;
  //if (Phylactere_col_r < 0) Phylactere_col_r = 0;
  if (Phylactere_col_r < 8) Phylactere_col_r = 8;
  Phylactere_col_g = ((cg * phylactere.transparency) + (phylactere.transparency_green * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_g > 255) Phylactere_col_g = 255;
  if (Phylactere_col_g < 0) Phylactere_col_g = 0;
  Phylactere_col_b = ((cb * phylactere.transparency) + (phylactere.transparency_blue * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_b > 255) Phylactere_col_b = 255;
  if (Phylactere_col_b < 0) Phylactere_col_b = 0;




I'm using AGS 3.4 r4.
#624
I'm using the Phylactere script to render speech which is normally used by Speak; and it works very well.
For my speechbubble background, I've chosen a translucent black; however, when it comes into contact with the black of a game background, it turns blue....? Why is it doing this?
Check this:


Here is my code:

Code: ags

// Require: AGS 3

Phylactere_Param phylactere;
export phylactere;

int Phylactere_col_r;
int Phylactere_col_g;
int Phylactere_col_b;

function game_start() {
  /* ------------- PARAMETRAGE --------------- */
  phylactere.background_color = 65535;
  phylactere.is_transparent = true;
  phylactere.outline_color = 0;
  phylactere.speed = 35;
  phylactere.transparency = 30;
  phylactere.transparency_red = 0;
  phylactere.transparency_green = 0;
  phylactere.transparency_blue = 0;
  phylactere.width = 300;
  phylactere.distance_from_head = 6;
  phylactere.view_speed = 5;
  phylactere.ajust_htext = 5;
  phylactere.skip_mode = eSkipKeyOrClick;
  /* ------------------------------------------ */
  
}

function getRVG(int color) {
  int c = color;
  if (c == -1) c = 63519;
  int cc = c / 2048;
  int cr , cg, cb;
  cr = cc * 8;
  c = c - (cc * 2048);
  cc = c / 64;
  cg = (cc * 8);
  c = c - (cc * 64);
  if (cg > 0) {
    cg += 4;
    c -= 32;
  }
  cb = c * 8;
  if (cb < 0) {
    if (cg > 4) cg -= 4;
    cb = 256 + cb;
  }
  Phylactere_col_r = ((cr * phylactere.transparency) + (phylactere.transparency_red * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_r > 255) Phylactere_col_r = 255;
  if (Phylactere_col_r < 0) Phylactere_col_r = 0;
  Phylactere_col_g = ((cg * phylactere.transparency) + (phylactere.transparency_green * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_g > 255) Phylactere_col_g = 255;
  if (Phylactere_col_g < 0) Phylactere_col_g = 0;
  Phylactere_col_b = ((cb * phylactere.transparency) + (phylactere.transparency_blue * (100 - phylactere.transparency))) / 100;
  if (Phylactere_col_b > 255) Phylactere_col_b = 255;
  if (Phylactere_col_b < 0) Phylactere_col_b = 0;
}

function Phylactere(this Character* , String str,  PhylactereQueueMode mode) {
 
  String speechnum;
 
  if (str.IndexOf("&") != -1) {
    speechnum = str.Substring(str.IndexOf("&"), str.IndexOf(" ")+1);
    str = str.Substring(str.IndexOf(" "), str.Length-1);
  } else {
    str = str.Copy();
  }

  
  if (IsTranslationAvailable()) str = GetTranslation(str);
 
  String GQueue[20]; // Dessin de la Queue (X = Contour, O = Fond)
  int queue_height = 0;
 
  if (mode == ePhylactereTalking) {
    GQueue[01] = "OOOOOOOO";
    GQueue[02] = "XOOOOOXX";
    GQueue[03] = "XOOOOX  ";
    GQueue[04] = "XOOOOX  ";
    GQueue[05] = " XOOOX  ";
    GQueue[06] = " XOOOX  ";
    GQueue[07] = "  XOOOX ";
    GQueue[08] = "   XOOOX";
    GQueue[09] = "    XXX ";
    queue_height = 9;
  }

  if (mode == ePhylactereThinking) {
    GQueue[01] = "        ";
    GQueue[02] = "        ";
    GQueue[03] = "  XX    ";
    GQueue[04] = " XOOX   ";
    GQueue[05] = "XOOOOX  ";
    GQueue[06] = "XOOOOX  ";
    GQueue[07] = " XOOX   ";
    GQueue[08] = "  XX    ";
    GQueue[09] = "        ";
    GQueue[10] = "    XX  ";
    GQueue[11] = "   XOOX ";
    GQueue[12] = "   XOOX ";
    GQueue[13] = "    XX  ";
    queue_height = 13;
  }
  
  // Controle des parametres
  if (phylactere.transparency < 0) phylactere.transparency = 0;
  if (phylactere.transparency > 100) phylactere.transparency = 100;
  if (phylactere.transparency_red < 0) phylactere.transparency_red = 0;
  if (phylactere.transparency_red > 255) phylactere.transparency_red = 255;
  if (phylactere.transparency_green < 0) phylactere.transparency_green = 0;
  if (phylactere.transparency_green > 255) phylactere.transparency_green = 255;
  if (phylactere.transparency_blue < 0) phylactere.transparency_blue = 0;
  if (phylactere.transparency_blue > 255) phylactere.transparency_blue = 255;
  if ((phylactere.skip_mode != eSkipTimer) && (phylactere.skip_mode != eSkipKeyOrClick) && (phylactere.skip_mode != eSkipOnlyKeyOrClick)) phylactere.skip_mode = eSkipTimer;

  // Arrêt du personnage si en mouvement
  if (phylactere.is_transparent) {
    if (this.Moving) this.StopMoving();
  }
  int char_x = this.x;
  int char_y = this.y;
  int view_x = GetViewportX();
  int view_y = GetViewportY();

  // Création de la surface
  DynamicSprite *screen = DynamicSprite.CreateFromBackground();
  DrawingSurface *surface = screen.GetDrawingSurface();
  surface.Clear();
  int screen_width = surface.Width;
  int screen_height = surface.Height;

  // Lance l'animation "Speech"
  if (this.SpeechView > 0) {
    if (mode != ePhylactereThinking) {
      this.LockView(this.SpeechView);
      this.Animate(this.Loop, phylactere.view_speed , eRepeat, eNoBlock);
    }
  }

  // Recupération de la hauteur du personnage
  ViewFrame *char_frame = Game.GetViewFrame(this.View , this.Loop, this.Frame);
  int char_height = FloatToInt(IntToFloat(Game.SpriteHeight[char_frame.Graphic]) * IntToFloat(this.Scaling) / 100.0);
  
  // Découpage de la phrase
  String line[101];
  int line_width[101];
  int line_height[101];
  int nb_lines = 0;
  String tmp_line = str.Substring(0, 1);
  String tmp_line2 = "";
  int ind_str = 1;
  int width_max = 0;
  int height_max = 0;
  while ((ind_str < str.Length) && (nb_lines < 99)) {
    tmp_line2 = tmp_line.AppendChar(str.Chars[ind_str]);
    if (GetTextWidth(tmp_line2, Game.SpeechFont) > phylactere.width) {
      int seek_blank = tmp_line.Length - 1;
      while (seek_blank > 0 && tmp_line.Chars[seek_blank] != ' ') {
        seek_blank--;
      }
      if (seek_blank > 0) {
        tmp_line2 = tmp_line.Substring(seek_blank + 1 , tmp_line.Length - seek_blank);
        tmp_line2 = tmp_line2.AppendChar(str.Chars[ind_str]);
        tmp_line = tmp_line.Substring(0, seek_blank);
      } else {
        tmp_line2 = "";
        tmp_line2 = tmp_line2.AppendChar(str.Chars[ind_str]);
      }
      nb_lines++;
      line[nb_lines] = tmp_line;
      line_width[nb_lines] = GetTextWidth(line[nb_lines], Game.SpeechFont);
      line_height[nb_lines] = GetTextHeight(line[nb_lines], Game.SpeechFont, screen_width);
      if (line_width[nb_lines] > width_max) width_max = line_width[nb_lines];
      height_max = height_max + line_height[nb_lines];
    }
    tmp_line = tmp_line2;
    tmp_line2 = "";
    ind_str++;
  }
  nb_lines++;
  line[nb_lines] = tmp_line;
  line_width[nb_lines] = GetTextWidth(line[nb_lines], Game.SpeechFont);
  line_height[nb_lines] = GetTextHeight(line[nb_lines], Game.SpeechFont, screen_width);
  if (line_width[nb_lines] > width_max) width_max = line_width[nb_lines];
  height_max = height_max + line_height[nb_lines];

  // Calcul positions du texte
  int texte_x = char_x - (width_max / 2) - GetViewportX();
  int texte_y = char_y - char_height - height_max - GetViewportY() - queue_height - phylactere.distance_from_head;
  if (texte_x < 0) texte_x = 0;
  if (texte_y < 0) texte_y = 0;
  if (texte_x + width_max + GetViewportX() > screen_width) texte_x = screen_width - width_max - GetViewportX();
  
  // Calcul positions de la bulle
  int bulle_x1 = texte_x - 5;
  int bulle_y1 = texte_y - 9 + phylactere.ajust_htext;    //CHEAT, set to 1
  int bulle_x2 = texte_x + width_max + 5;
  int bulle_y2 = texte_y + height_max + phylactere.ajust_htext;
  
  // ---- Bulle ----
  DrawingSurface* background_surface;
  DynamicSprite* background_sprite;
  
  if (phylactere.is_transparent) {
    bool mouse_visible_before = Mouse.Visible;
    if (mouse_visible_before) Mouse.Visible = false;
    //Wait(1);
    background_sprite = DynamicSprite.CreateFromScreenShot();
    if (mouse_visible_before) Mouse.Visible = true;
    background_surface = background_sprite.GetDrawingSurface();
    int by = bulle_y1;
    int bx;
    while (by <= bulle_y2) {
      bx = bulle_x1;
      while (bx <= bulle_x2) {
        int col = background_surface.GetPixel(bx, by);
        getRVG(col);
        surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
        surface.DrawPixel(bx, by);
        bx++;
      }
      by++;
    }
    
    bx = bulle_x1 - 1;
    by = bulle_y1 + 1;
    while (by <= bulle_y2 - 1) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      by++;
    }

    bx = bulle_x2 + 1;
    by = bulle_y1 + 1;
    while (by <= bulle_y2 - 1) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      by++;
    }

    bx = bulle_x1 + 1;
    by = bulle_y1 - 1;
    while (bx <= bulle_x2 - 1) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      bx++;
    }

    bx = bulle_x1 + 1;
    by = bulle_y2 + 1;
    while (bx <= bulle_x2 - 1) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      bx++;
    }

    bx = bulle_x1 - 2;
    by = bulle_y1 + 3;
    while (by <= bulle_y2 - 3) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      by++;
    }

    bx = bulle_x2 + 2;
    by = bulle_y1 + 3;
    while (by <= bulle_y2 - 3) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      by++;
    }

    bx = bulle_x1 + 3;
    by = bulle_y1 - 2;
    while (bx <= bulle_x2 - 3) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      bx++;
    }

    bx = bulle_x1 + 3;
    by = bulle_y2 + 2;
    while (bx <= bulle_x2 - 3) {
      int col = background_surface.GetPixel(bx, by);
      getRVG(col);
      surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
      surface.DrawPixel(bx, by);
      bx++;
    }

  } else {
    surface.DrawingColor = phylactere.background_color;
    surface.DrawRectangle(bulle_x1 , bulle_y1 ,  bulle_x2 ,  bulle_y2);
    surface.DrawLine(bulle_x1 - 1, bulle_y1 + 1 ,  bulle_x1 - 1 ,  bulle_y2 - 1);
    surface.DrawLine(bulle_x2 + 1, bulle_y1 + 1 ,  bulle_x2 + 1 ,  bulle_y2 - 1);
    surface.DrawLine(bulle_x1 + 1 ,  bulle_y1 - 1 ,  bulle_x2 - 1 ,  bulle_y1 - 1);
    surface.DrawLine(bulle_x1 + 1 ,  bulle_y2 + 1 ,  bulle_x2 - 1 ,  bulle_y2 + 1);
    surface.DrawLine(bulle_x1 - 2, bulle_y1 + 3 ,  bulle_x1 - 2 ,  bulle_y2 - 3);
    surface.DrawLine(bulle_x2 + 2, bulle_y1 + 3 ,  bulle_x2 + 2 ,  bulle_y2 - 3);
    surface.DrawLine(bulle_x1 + 3 ,  bulle_y1 - 2 ,  bulle_x2 - 3 ,  bulle_y1 - 2);
    surface.DrawLine(bulle_x1 + 3 ,  bulle_y2 + 2 ,  bulle_x2 - 3 ,  bulle_y2 + 2);
  }

  // ---- Contours ----
  surface.DrawingColor = phylactere.outline_color;
  surface.DrawLine(bulle_x1 - 3, bulle_y1 + 3 ,  bulle_x1 - 3 ,  bulle_y2 - 3);
  surface.DrawLine(bulle_x2 + 3, bulle_y1 + 3 ,  bulle_x2 + 3 ,  bulle_y2 - 3);
  surface.DrawLine(bulle_x1 + 3 ,  bulle_y1 - 3 ,  bulle_x2 - 3 ,  bulle_y1 - 3);
  surface.DrawLine(bulle_x1 + 3 ,  bulle_y2 + 3 ,  bulle_x2 - 3 ,  bulle_y2 + 3);
  
  //---- Angle supérieur gauche ----
  surface.DrawPixel(bulle_x1 - 2 , bulle_y1 + 2);
  surface.DrawPixel(bulle_x1 - 2 , bulle_y1 + 1);
  surface.DrawPixel(bulle_x1 - 1 , bulle_y1);
  surface.DrawPixel(bulle_x1 , bulle_y1 - 1);
  surface.DrawPixel(bulle_x1 + 1 , bulle_y1 - 2);
  surface.DrawPixel(bulle_x1 + 2 , bulle_y1 - 2);

  //---- Angle supérieur droit ----
  surface.DrawPixel(bulle_x2 + 2 , bulle_y1 + 2);
  surface.DrawPixel(bulle_x2 + 2 , bulle_y1 + 1);
  surface.DrawPixel(bulle_x2 + 1 , bulle_y1);
  surface.DrawPixel(bulle_x2 , bulle_y1 - 1);
  surface.DrawPixel(bulle_x2 - 1 , bulle_y1 - 2);
  surface.DrawPixel(bulle_x2 - 2 , bulle_y1 - 2);

  //---- Angle inférieur gauche ----
  surface.DrawPixel(bulle_x1 - 2 , bulle_y2 - 2);
  surface.DrawPixel(bulle_x1 - 2 , bulle_y2 - 1);
  surface.DrawPixel(bulle_x1 - 1 , bulle_y2);
  surface.DrawPixel(bulle_x1 , bulle_y2 + 1);
  surface.DrawPixel(bulle_x1 + 1 , bulle_y2 + 2);
  surface.DrawPixel(bulle_x1 + 2 , bulle_y2 + 2);

  //---- Angle inférieur droit ----
  surface.DrawPixel(bulle_x2 + 2 , bulle_y2 - 2);
  surface.DrawPixel(bulle_x2 + 2 , bulle_y2 - 1);
  surface.DrawPixel(bulle_x2 + 1 , bulle_y2);
  surface.DrawPixel(bulle_x2 , bulle_y2 + 1);
  surface.DrawPixel(bulle_x2 - 1 , bulle_y2 + 2);
  surface.DrawPixel(bulle_x2 - 2 , bulle_y2 + 2);
  
  // ---- Queue ----
  int char_dir = this.Loop; // 0=bas , 1=gauche, 2=droite, 3=haut
  int qy = bulle_y2 + 3;
  int qx;
  if ((char_dir == 1) || (char_dir == 0)) {
    qx = char_x - 10 - GetViewportX();
  } else {
    qx = char_x + 10 - GQueue[1].Length - GetViewportX();
  }
  int j = 1;
  while (j <= queue_height) {
    int i = 0; 
    while (i < GQueue[j].Length) {
      bool visible = false;
      if (GQueue[j].Chars[i] == 'X') {
        surface.DrawingColor = phylactere.outline_color;
        visible = true;
      }
      if (GQueue[j].Chars[i] == 'O') {
        if (phylactere.is_transparent) {
          int col;
          if ((char_dir == 1) || (char_dir == 0)) {
            col = background_surface.GetPixel(qx + i ,  qy + j - 1);
          } else {
            col = background_surface.GetPixel(qx + GQueue[j].Length - i ,  qy + j - 1);
          }
          getRVG(col);
          surface.DrawingColor = Game.GetColorFromRGB(Phylactere_col_r, Phylactere_col_g, Phylactere_col_b);
        } else {
          surface.DrawingColor = phylactere.background_color;
        }
        visible = true;
      }
      if (visible) {
        if ((char_dir == 1) || (char_dir == 0)) {
          surface.DrawPixel(qx + i ,  qy + j - 1);
        } else {
          surface.DrawPixel(qx + GQueue[j].Length - i ,  qy + j - 1);
        }
      }
      i++; 
    }
    j++;
  }
  if (phylactere.is_transparent) {
    background_surface.Release();
    background_sprite.Delete();
  }

  // Texte
  surface.DrawingColor = this.SpeechColor;
  int ii = 0;
  int jj = 0;
  while (ii < nb_lines) {
    ii++;
    surface.DrawString(texte_x + (width_max - line_width[ii]) / 2 , texte_y + jj , Game.SpeechFont ,  line[ii]); 
    jj = jj + line_height[ii]; 
  }

  // Affichage de la bulle
  int pos_x = bulle_x1 - 4;
  if (pos_x < 0) pos_x = 0;
  int pos_y = bulle_y1 - 4;
  if (pos_y < 0) pos_y = 0;
  int lng_x = bulle_x2 + 4;
  int lng_y = bulle_y2 + 4 + queue_height;
  
  if (lng_x >= screen_width) lng_x = screen_width - 1;
  if (lng_y >= screen_height) lng_y = screen_height - 1;

  DynamicSprite* ds = DynamicSprite.CreateFromDrawingSurface(surface, pos_x, pos_y, lng_x - pos_x + 1 ,  lng_y - pos_y + 1);
  surface.Release();
  Overlay* bulle = Overlay.CreateGraphical(pos_x, pos_y, ds.Graphic, true);

  // Attente
  int tempo = FloatToInt(IntToFloat(str.Length) * IntToFloat(phylactere.speed) / 10.0);
  if (tempo < 40) tempo = 40;
  bool stop = false;
  
  if (speechnum != null) {
    this.SaySync(speechnum.Append(str));  
    this.Say(speechnum);                  //speak the line
  }
  
  if (speechnum==null) {  
    while (!stop){
      if (!phylactere.is_transparent) {
        bulle.Remove();
        int nx = pos_x + (this.x - char_x) - (GetViewportX() - view_x);
        int ny = pos_y + (this.y - char_y) - (GetViewportY() - view_y);
        bulle = Overlay.CreateGraphical(nx, ny, ds.Graphic, true);
      }
      if (phylactere.skip_mode != eSkipOnlyKeyOrClick) tempo--;
      if (phylactere.skip_mode == eSkipKeyOrClick) {
        int wm = WaitMouseKey(1);
        if (wm == 1) stop = true;
      }
      if (phylactere.skip_mode == eSkipTimer) {
        Wait(1);
      }
      if (tempo == 0) stop = true;
    }
  }
  
  // Efface la bulle
  ds.Delete();
  screen.Delete();
  bulle.Remove();
  
  // Arrete l'animation Speech
  if (this.SpeechView > 0) {
    if (mode != ePhylactereThinking) {
      this.UnlockView();
    }
  }
  Wait(1);
    
}


As you can see I've only changed about 5 lines of code to integrate in the numbered speech system, but I thought I should post all.

You can get Phylactere here.
#625
Here's the final working code:

Beach:
Code: ags


function room_FirstLoad()
{
  SetGameOption(OPT_CROSSFADEMUSIC, 2);
  chan1=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
  chan2=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
}

function room_AfterFadeIn()
{
	if (cJulius.PreviousRoom == CAVE) {
		aWater_dripping.Stop();
		if (chan2!=null) {
			chan2=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
		}
	}
	
}


Cave:
Code: ags

	
function room_AfterFadeIn()
{
	if (cJulius.PreviousRoom == BEACH) {
		chan2=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
	} 
	
	if (chan1.PlayingClip!=aWater_dripping) {
		chan1=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
	}

}

function room_RepExec()
{
	beachThemePos=chan2.Position+1100;
}
#626
Here's the final working code:

Beach:
Code: ags


function room_FirstLoad()
{
  SetGameOption(OPT_CROSSFADEMUSIC, 2);
  chan1=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
  chan2=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
}

function room_AfterFadeIn()
{
	if (cJulius.PreviousRoom == CAVE) {
		aWater_dripping.Stop();
		if (chan2!=null) {
			chan2=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
		}
	}
	
}


Cave:
Code: ags

	
function room_AfterFadeIn()
{
	if (cJulius.PreviousRoom == BEACH) {
		chan2=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
	} 
	
	if (chan1.PlayingClip!=aWater_dripping) {
		chan1=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
	}

}

function room_RepExec()
{
	beachThemePos=chan2.Position+1100;
}
#627
Hi

I've written the folowing code for 2 rooms, Cave and Beach. Player starts out in Beach. The same song (or a very similar version called a1_beachTheme_5_0_CAVE) plays in Cave at exactly the same position; I keep the global variable beachThemePos to track the current position in the audio.

My question is:
a) why does it crash with 'beachThemePos' directly after I play 'chan1=a1_beachTheme_5_......'  ?  I initalise the variable; still crashes. I make sure MaxChannels is 50; still crashes.
b) how do I keep track of a track's position number? I thought it was by typing beachThemePos=chan1.PositionMs, but obviously not. It gives a position in the current track - but can I track this to be the one playing 'a1_beachTheme_...'? If a track is position [4], how do I make sure when I seek, it always does this to position 4? adiochannel.seek[4]? No idea how this works.

Beach:
Code: ags

function room_FirstLoad()
{
    SetGameOption(OPT_CROSSFADEMUSIC, 2);
}
 
function room_AfterFadeIn()
{
  if (cJulius.PreviousRoom == CAVE) {
    aWater_dripping.Stop();
  }
 
  if (chan1==null) {
    chan1=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityHigh, eRepeat);
    chan1=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);    //run the first time I'm in Bach -- ie. after game loads
  } else {
    chan1=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);    //runs every time after that
  }             
}
 
function room_RepExec()
{
  beachThemePos=chan1.PositionMs;
}



Cave:
Code: ags

function room_AfterFadeIn()
{
  if (cJulius.PreviousRoom == BEACH) {
    chan1=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  } 
        
  if (chan1.PlayingClip!=aWater_dripping) {
    chan1=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  }
}
 
function room_RepExec()
{
  beachThemePos=chan1.PositionMs;
}
#628
Okay, I've learnt more about the audiochannel system, and edited my code.

It all works -- except that the beach_theme is restarted every time I enter room 2 (Beach) from room 7 (Cave). You start in Beach.
Cave works fine; beach does not.

Beach:
Code: ags

function room_FirstLoad()
{
    SetGameOption(OPT_CROSSFADEMUSIC, 2);
}

function room_AfterFadeIn()
{
  if (cJulius.PreviousRoom == CAVE) {
    aWater_dripping.Stop();
  }

  if (chan1==null) {
    chan1=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityHigh, eRepeat);
    chan1=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);    //run the first time I'm in Bach -- ie. after game loads
  } else {
    chan1=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);    //runs every time after that
  }		
}

function room_RepExec()
{
  beachThemePos=chan1.PositionMs;
}



Cave:
Code: ags

function room_AfterFadeIn()
{
  if (cJulius.PreviousRoom == BEACH) {
    chan1=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  } 
	
  if (chan1.PlayingClip!=aWater_dripping) {
    chan1=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  }
}

function room_RepExec()
{
  beachThemePos=chan1.PositionMs;
}
#629
Crimson, Snarky, what do you suggest?
#630
Aha, the points worked! Reduced it to 5 - works now :)

I'm still having a problem with the below code for two rooms.
Room 2 is BEACH
Room 7 is CAVE
a1_beachTheme_5_0 is a theme for the room BEACH, type Music. Music MaxChannel is 1.
aOcean_crash is a theme for BEACH, type Sound. It continues in BEACH or CAVE, but it set off in BEACH. Sound MaxChannels is 5.

in CAVE,
a1_beachTheme_5_0_CAVE is a lower volume, muffled one than the original. It's kept in sync with beachThemePos; this way, when music play's, it slips seemlessly from one to the other.
aWater_dripping is a sound effect, type Sound.

I use 3 AudioChannel* variables, called chan1, chan2 and chan3. Chan1 is a continuous Music channel that crossfades between rooms, using the standard game option.
Chan2 is for sound effects, and chan3 is an extra one.

I know this isn't the best solution, but usually it's just music and nothing else, and I cannot get my head around rising/falling channels, Tween, etc.

The problem is: chan2 initially plays the Water_dripping sound effect; but then, regardless that it's non-null, it stops after the 2nd or 3rd time. After this, it causes an error at the 5th time, saying it is null.

I'm guessing that chan2 is not 'static', and that I'm getting it to reach the MaxChannel limit and then crash with an erronious error. But then....?
Whatever I do, chan2 crashes erroniously, eventually.
What's causing it?

No idea what's going on.

Beach - room_load():
Code: ags

	if (cJulius.PreviousRoom == 7) {
		chan1 = a1_beachTheme_5_0.Play(eAudioPriorityNormal, eRepeat);
		chan1.Seek(beachThemePos);
		if (chan2.PlayingClip==aWater_dripping) {
			chan2.Stop();
		}
	} else {
		if (chan1 != null) {
			if (chan1.PlayingClip!=a1_beachTheme_5_0) {
				chan1 = a1_beachTheme_5_0.Play(eAudioPriorityNormal, eRepeat);
			}
		} else {
			chan1 = a1_beachTheme_5_0.Play(eAudioPriorityNormal, eRepeat);
		}
	}
	
	if (chan3!=null) {
		if (chan3.PlayingClip != aOcean_crash_cave) {
			chan3 = aOcean_crash.Play(eAudioPriorityHigh, eRepeat);
		} 
	} else {
		chan3 = aOcean_crash.Play(eAudioPriorityHigh, eRepeat);
	}


Cave - room_load():
Code: ags

	if (cJulius.PreviousRoom == 2) {
		chan1 = a1_beachTheme_5_0_CAVE.Play(eAudioPriorityNormal, eRepeat);
		chan1.Seek(beachThemePos);
	} else {
		if (chan1!=null) {
			if (chan1.PlayingClip != a1_beachTheme_5_0_CAVE) {
				chan1 = a1_beachTheme_5_0_CAVE.Play(eAudioPriorityNormal, eRepeat);
			} else {
				chan1 = a1_beachTheme_5_0_CAVE.Play(eAudioPriorityNormal, eRepeat);
			}
		}
	}
	
	if (chan2 != null) {
    if (chan2.PlayingClip!=aWater_dripping) {
      chan2 = aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
    }
  } else {
    chan2 = aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  }	
#631
Hi Kris, the function Game.SetAudioTypeSpeechVolumeDrop(AudioType, int volumeReduction):
a) set to 80, just as loud
b) while speech occurs, the audio is completely blanked out.
#632
Background speech?... Is this like a speech style, like Thinking?
Could you give me a function name?
#633
Hi,

I'm having a problem with my music while speech is being played. This isn't just the suond volume during a dialog; it's during actua speech.
I thought there must be any easy way to fix this (10% volume during speech, 100% rest of time), but can't find the option is Game options or anywhere else.
Can sound volume be altered during a dialog and/or during speech play?

Thank you :)
#635
Here's the final working code - bug's that drove me insane removed - for anyone dumber even than me who wants an example :P

Code: ags

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  info.X = 0;
  info.Y = 704;
  info.Width = 1024;
  info.Height = 64;
}

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  int i = 1, ypos=0, xpos=0;
  info.Surface.Clear(15);	
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      String str = info.DialogToRender.GetOptionText(i);
      int cur_img = str.AsInt;
      info.Surface.DrawImage(xpos, ypos, cur_img);
      xpos+=64;
    }
    i++;
  }
}

function dialog_options_repexec(DialogOptionsRenderingInfo *info)
{
  int i = 1,  xpos = 0;
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (mouse.y >= info.Y && mouse.x >= xpos && mouse.x <= xpos+64)
      {
        info.ActiveOptionID = i;
        return;
      }
      xpos+=64;
    }
    i++;
  }
}

function dialog_options_mouse_click(DialogOptionsRenderingInfo *info, MouseButton button)
{
  if (info.ActiveOptionID > 0) {
    info.RunActiveOption();
  } else {
    return;
  }
}
#636
...it's because of the options had no Stop on them :P
Always have one Stop.
#637
Before there was nothing; now, it shows this:

"An error has occured.
ACI 3.4.0.16 NMP
Error: DoDialog: all options haave been turned off."

It just closes the program.
#638
Code updated and working :)

Code: ags

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  // Create a 1024x128 dialog options area at (1,640)
  info.X = 1;
  info.Y = 640;
  info.Width = 1024;
  info.Height = 128;
}

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  int i = 1,  ypos = 0, xpos=0;
  info.Surface.Clear(16);	
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      String str = info.DialogToRender.GetOptionText(i);
      int cur_img = str.AsInt;
      info.Surface.DrawImage(xpos, ypos, cur_img);
      xpos=xpos+128;
    }
    i++;
  }
}

function dialog_options_repexec(DialogOptionsRenderingInfo *info)
{  
  int i = 1,  xpos = 0;
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (mouse.y>info.Y && mouse.x >= xpos && mouse.x<=xpos+128)
      {
        info.ActiveOptionID = i;
        return;
      }
      xpos+=128;
    }
    i++;
  }
}

function dialog_options_mouse_click(DialogOptionsRenderingInfo *info, MouseButton button)
{
    if (info.ActiveOptionID > 0) {
      info.RunActiveOption();
    } else {
      return;
    }
}



However - when I have 2 options left, it crashes. Normal behaviour is say one; then, since there's only one left, say that; quit dialog.
What actually happens is: say one; then say the other; no options left - crash.
:/
#639
Thanks :)

Here's what I have so far:

Code: ags

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  // Create a 1024x128 dialog options area at (1,640)
  info.X = 1;
  info.Y = 640;
  info.Width = 1024;
  info.Height = 128;
}

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  int i = 1,  ypos = 0, xpos=0;
  info.Surface.Clear(15);	
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      String str = info.DialogToRender.GetOptionText(i);
      int cur_img = str.AsInt;
      info.Surface.DrawImage(xpos, ypos, cur_img);
      xpos=xpos+128;
    }
    i++;
  }
}

function dialog_options_get_active(DialogOptionsRenderingInfo *info)
{
  int i = 1,  xpos = 0;
  // Find the option that corresponds to where the player clicked
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (mouse.y>info.Y && mouse.x >= xpos && mouse.x<=xpos+128)
      {
        info.ActiveOptionID = i;
        Display("%d",info.ActiveOptionID);
        return;
      }
      xpos+=128;
    }
    i++;
  }
}


It displays several 128x128 images next to eachother at the bottom, each corresponding to an answer. The images have the sprite slot number as the option text. Selecting each image/answer plays a piece of pre-recorded dialog.

However, dialog_options_get_active doesn't do anything. It doesn't pick where a user clicked (wherever you click, the dialog does nothing), and it doesn't even display the active option (once you've clicked it, which it doesn't do).

Have I missed something?
#640
I'm still working my way through the custom dialogue tree (http://www.adventuregamestudio.co.uk/manual/ags44.htm) - but one question, what about image buttons for dialogue choices?
I imagine you could write a sprite number in the question part of the dialogue, then use this to dig the sprite out and use it for the image on the dialogue choice. But how? How do you refer to an image in the sprite file, image.Graphic? Is there a script or plugin to do this already?
SMF spam blocked by CleanTalk