Author Topic: Trouble wiping custom Dialog Options 'after-image' from background  (Read 302 times)

bx83

  • Get 'Er Doooooone
I'm having trouble, once again, getting the custom dialog rendering options to work.

I first wanted to get an image of the current dialog options, and then keep them there in place while speech continued.
However, since changing the background colour from white to transparent, an 'after image' of my previous option set sits on screen, 'under' the new set of options. (the after-image button graphics are non-functional)

The after image is cleared again when an option is picked.
The after-image lasts between when speech ends, and when the next option is chosen; the speech then starts for this option.

I've tried a few things, and I know the answer is staring me in the face, but I just can't find out where, or what, to put to wipe the after-image options.

Here's a link to my viedo, to demostrate what's happening:
http://redrom.ltd/img/dialog error.webm

Here is my code:
gFakeDialogOptions is a GUI 1366x96 box, that's colour 0
MyDynamicSpriteForTheFakeGUI is a global DynamicSprite*

Code: Adventure Game Studio
  1. //----------------------------------------------------------------------------------------------------------------------
  2. // Dialog Options Get Dimensions
  3. //----------------------------------------------------------------------------------------------------------------------
  4.  
  5. function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
  6. {
  7.  
  8. // Create a 1366x64 dialog options area at (0,704)
  9.  
  10.   info.X = 0;
  11.   info.Y = 672;
  12.   info.Width = 1366;
  13.   info.Height = 96;
  14. }
  15.  
  16. //----------------------------------------------------------------------------------------------------------------------
  17. // Draw Dialog Options
  18. //----------------------------------------------------------------------------------------------------------------------
  19.  
  20. function DrawDialogOptions(DrawingSurface* ds, DialogOptionsRenderingInfo* info)
  21. {
  22.   int i = 1, ypos = 0, xpos = 0;  
  23.   ds.Clear(COLOR_TRANSPARENT);
  24.   while (i <= info.DialogToRender.OptionCount)
  25.   {
  26.     if (info.DialogToRender.GetOptionState(i) == eOptionOn)
  27.     {
  28.       String str = info.DialogToRender.GetOptionText(i);  //get glyph number from option text
  29.       int cur_img = str.AsInt;                            //current image is that number
  30.       ds.DrawImage(xpos, ypos, cur_img);                  //draw this glyph
  31.       xpos += 96;                                         //xpos+=width of glyph
  32.     }
  33.     i++;
  34.   }    
  35. }
  36.  
  37. //----------------------------------------------------------------------------------------------------------------------
  38. // Dialog Options Render
  39. //----------------------------------------------------------------------------------------------------------------------
  40.  
  41. function dialog_options_render(DialogOptionsRenderingInfo* info)
  42. {
  43.   DrawDialogOptions(info.Surface, info);
  44. }
  45.  
  46. //----------------------------------------------------------------------------------------------------------------------
  47. // Dialog Options Repeat Exec
  48. //----------------------------------------------------------------------------------------------------------------------
  49.  
  50. function dialog_options_repexec(DialogOptionsRenderingInfo* info)
  51. {
  52.   int i = 1, xpos = 0;
  53.   while (i <= info.DialogToRender.OptionCount)
  54.   {
  55.     if (info.DialogToRender.GetOptionState(i) == eOptionOn)
  56.     {
  57.       if (mouse.y >= info.Y && mouse.x >= xpos && mouse.x <= xpos+96)
  58.       {
  59.         info.ActiveOptionID = i;
  60.         return;
  61.       }
  62.       xpos += 96;
  63.     }
  64.     i++;
  65.   }
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------------------------------------
  69. // Dialog Options Mouse Click
  70. //----------------------------------------------------------------------------------------------------------------------
  71.  
  72. function dialog_options_mouse_click(DialogOptionsRenderingInfo* info, MouseButton button)
  73. {
  74.   if (info.ActiveOptionID > 0)
  75.   {
  76.     MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
  77.     DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
  78.     DrawDialogOptions(ds, info);
  79.     ds.Release();
  80.  
  81.     gFakeDialogOptions.BackgroundGraphic = MyDynamicSpriteForTheFakeGUI.Graphic;
  82.     gFakeDialogOptions.Visible = true;
  83.     info.RunActiveOption();
  84.   }
  85. }

Any help will be welcome.

Scavenger

  • Cavefish
  • In Four Glorious Colours!
    • I can help with animation
    • I can help with backgrounds
    • I can help with characters
    • I can help with scripting
    • Scavenger worked on one or more games that won an AGS Award!
    •  
    • Scavenger worked on one or more games that was nominated for an AGS Award!
Well, one thing I am noticing is that you don't get rid of the DynamicSprite before creating a new one, which will lead to memory leaks. Run this before creating a new sprite:

Code: Adventure Game Studio
  1. if (MyDynamicSpriteForTheFakeGUI != null) MyDynamicSpriteForTheFakeGUI.Delete();

Also, in dialog_options_repexec, add:

Code: Adventure Game Studio
  1. gFakeDialogOptions.Visible = false;

The after image is because you're not actually turning off the GUI before displaying the new dialog options, so it's still there underneath them.

Well, one thing I am noticing is that you don't get rid of the DynamicSprite before creating a new one, which will lead to memory leaks.

It really should not, managed objects are reference counted, so they all got deleted automatically as soon as the number of references reaches zero.

bx83

  • Get 'Er Doooooone
Thankyou guys, belatedly :)
Works a treat :)

Code: Adventure Game Studio
  1. function dialog_options_repexec(DialogOptionsRenderingInfo* info)
  2. {
  3.   int i = 1, xpos = 0;
  4.   while (i <= info.DialogToRender.OptionCount)
  5.   {
  6.     if (info.DialogToRender.GetOptionState(i) == eOptionOn)
  7.     {
  8.       if (mouse.y >= info.Y && mouse.x >= xpos && mouse.x <= xpos+96)
  9.       {
  10.         info.ActiveOptionID = i;
  11.         return;
  12.       }
  13.       xpos += 96;
  14.     }
  15.     i++;
  16.   }
  17.   gFakeDialogOptions.Visible = false;    //THIS LINE ADDED, THAT'S IT
  18. }