Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Fri 06/02/2015 15:30:50

Title: [Fixed] Transparent background in custom speech...
Post by: Technocrat on Fri 06/02/2015 15:30:50
Hello! I've been attempting to engineer a customised dialogue-selection system using instructions from the manual, and am about half-way to succeeding. It will create the GUI in the right place on the screen.

(http://i116.photobucket.com/albums/o33/Nedraed/img1_zpswve53g3s.png)

Code (ags) Select

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  // Clear the area black
  //info.Surface.Clear(32);
  int i = 1,  ypos = 0;
  // Render all the options that are enabled
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (info.ActiveOptionID == i) info.Surface.DrawingColor = 46911;
      else info.Surface.DrawingColor = 782;
      info.Surface.DrawStringWrapped(5, ypos, info.Width - 10,
                         eFontFont0, eAlignLeft, info.DialogToRender.GetOptionText(i));
      ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontFont0, info.Width - 10);
    }
    i++;
  }
}



I want to make the blackness transparent. In order to accomplish this, I've created a sprite to use as the background for it, but when I change the script to use it, nothing appears.

(http://i116.photobucket.com/albums/o33/Nedraed/img2_zpscmynxww0.png)

Code (ags) Select

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  info.Surface.Clear(COLOR_TRANSPARENT);
  info.Surface.DrawImage(0, 66, 115, 15, 640, 120);
  int i = 1,  ypos = 0;
  // Render all the options that are enabled
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (info.ActiveOptionID == i) info.Surface.DrawingColor = 46911;
      else info.Surface.DrawingColor = 782;
      info.Surface.DrawStringWrapped(5, ypos, info.Width - 10,
                         eFontFont0, eAlignLeft, info.DialogToRender.GetOptionText(i));
      ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontFont0, info.Width - 10);
    }
    i++;
  }
}



The effect *should*, as far as I can tell, create a transparent version of that black bar. I've tried using other sprites as well, but nothing appears on the screen. Is there something I'm missing? Alternatively, is there a means by which to make the black background drawn on the surface partially transparent?

Many thanks!
Title: Re: Transparent background in custom speech...
Post by: Snarky on Fri 06/02/2015 15:46:52
The code looks correct, so I'd check a few things:

1. The game is 32-bit?
2. How are you creating the drawing surface? From a dynamic sprite? When you do that, are you making sure to create it with an alpha channel?
3. The sprite you're trying to draw, it was imported as a 32-bit sprite? (Not sure that this is necessary, but it doesn't hurt.)

The other way to go about this is to make the background sprite semi-transparent in the first case. Unfortunately there's no way to rawdraw a rectangle with transparency directly, so you always have to use DrawImage to do so.
Title: Re: Transparent background in custom speech...
Post by: Technocrat on Fri 06/02/2015 15:58:37
The game is definitely 32-bit, and as far as I know, the sprite's been imported as a 32-bit one. I've not seen any means to import them any other ways?


I'm fairly terrible with drawing surfaces, but as far as I can tell, this is the script that creates the...thing...in which the background is drawn. Should I be using a dynamic sprite separately?

Code (AGS) Select

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  // Create a 400x120 dialog options area at (0,66)
  info.X = 0;
  info.Y = 66;
  info.Width = 640;
  info.Height = 120;
  // Enable alpha channel for the drawing surface
  info.HasAlphaChannel = true;

}
Title: Re: Transparent background in custom speech...
Post by: Snarky on Fri 06/02/2015 16:43:20
No, I just didn't look closely enough into the custom dialog rendering (I agree the system is pretty confusing; I always have to look up the differences between a Drawing Surface and Dynamic Sprite).

To import a sprite in 32-bit, make sure the file you're importing has an alpha channel, and choose the "use alpha channel" (or whatever it's called) when you import.

What version are you using? The online manual doesn't have an info.HasAlphaChannel property, so 3.3 or higher? I don't think I can help, but it sounds like you might be experiencing a variation of this: http://www.adventuregamestudio.co.uk/forums/index.php?topic=47666.msg636470331#msg636470331
Title: Re: Transparent background in custom speech...
Post by: Technocrat on Fri 06/02/2015 17:10:56
Indeed, I'm using 3.3.2.

Managed to get it working - Turns out that the "transparency" value in the function wasn't being helpful; 0 would make it opaque, and anything higher made it completely invisible. So, I took the other approach, and imported the sprite with its own alpha-transparency. Now, it works perfectly!

Thank you for your help!
Title: Re: Transparent background in custom speech...
Post by: monkey0506 on Fri 06/02/2015 17:24:43
A couple of things...

*) You're drawing the image at (0, 66) in the DrawingSurface. You probably want to draw it at (0, 0). The coordinates to DrawImage are relative to the surface, not the screen.
*) Does it make any difference if you change the transparency? Does it appear if you draw the sprite fully opaque?

Edit: You ninja-posted on me. Anyway, that sounds familiar. I think I reported that same behavior some time ago...

Edit 2: Don't recall if I created a tracker entry for it, but I did create a thread (http://www.adventuregamestudio.co.uk/forums/index.php?topic=50548.msg636489444#msg636489444). This is definitely a bug, and I don't know if anyone ever looked into it. (Sorry, I'm posting while working on a school project, so I'm mildly distracted ;))
Title: Re: [Fixed] Transparent background in custom speech...
Post by: Crimson Wizard on Fri 06/02/2015 17:36:00
Quote from: Technocrat on Fri 06/02/2015 17:10:56
Managed to get it working - Turns out that the "transparency" value in the function wasn't being helpful; 0 would make it opaque, and anything higher made it completely invisible.

Quote from: monkey_05_06 on Fri 06/02/2015 17:24:43
Edit 2: Don't recall if I created a tracker entry for it, but I did create a thread (http://www.adventuregamestudio.co.uk/forums/index.php?topic=50548.msg636489444#msg636489444). This is definitely a bug, and I don't know if anyone ever looked into it.

This was dealt with in 3.4.0.2:
Quote from: Crimson Wizard on Wed 12/11/2014 18:51:29
* In 32-bit games DrawingSurface.DrawImage() now properly applies overall transparency when drawing opaque sprites over surfaces with alpha channel.
It was not a bug in the sense that it was originally programmed to work that way. But, ofcourse, it was a mistake in general sense.
Title: Re: [Fixed] Transparent background in custom speech...
Post by: Snarky on Fri 06/02/2015 17:43:59
Quote from: Crimson Wizard on Fri 06/02/2015 17:36:00
It was not a bug in the sense that it was originally programmed to work that way.

Ah, the old "works as programmed"! Not perhaps the strictest criterion for code correctness. ;)