[SOLVED] Drawing onto the background of a GUI

Started by Monsieur OUXX, Mon 10/06/2013 17:47:24

Previous topic - Next topic

Monsieur OUXX

Hi,

In my 32-bit game,  created two GUIs with those features:
GUI #1 :
  - background color: 0
  - background color number: 0;0;0
  - background image: 666 (this is a picture that's entirely transparent -- it's all pink)

GUI #2:
  - background color: 0
  - background color number: 0;0;0
  - background image: 777 (this is a picture that is almost entirely transparent, with just a few colored pixels in the top-left corner)

Note: In the code, I have a variable _renderingGui that can point to either GUI#1 or GUI#2 depending on the needs of the test.

At the very beginning of the game execution, I do this once, to take a screenshot of the GUI background:
Code: AGS

   DynamicSprite* bgSnapshot; //global variable, used later

  DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(_renderingGui.BackgroundGraphic);
  DrawingSurface *surface = sprite.GetDrawingSurface();
  if (bgSnapshot == null) { //very first time
    bgSnapshot =        DynamicSprite.CreateFromDrawingSurface(
                          surface, 0, 0,
                          surface.Width,  surface.Height
                          );
  }


Then, in repeatedly_execute_always, I do this:
Code: AGS

    DynamicSprite* sprite; //global variable

    ...

    sprite = DynamicSprite.CreateFromExistingSprite(_renderingGui.BackgroundGraphic);
    DrawingSurface *surface = sprite.GetDrawingSurface();

    redrawBackground(surface); //this draws [i]bgSnapshot[/i] back into [i]surface[/i]
    DrawStuff(surface); //this draws shapes and stuff onto [i]surface[/i]

   surface.Release();
   _renderingGui.BackgroundGraphic = sprite.Graphic;


I observe a very weird behaviour that I can't explain:

- When I run this code with _renderingGui being GUI#1, then I can see all the stuff that gets drawn in DrawStuff(); Apparently, the fact that the background image of the GUI is completely transparent has something to do with it: I'm almost certain that nothing gets drawn during redrawBackground(), because when I draw more and more stuff in DrawStuff() at each loop, the stuff drawn in the previous loop is still visible below.
- When I run this code with _renderingGui being GUI#2, then I can only see the background image of the gui. All the stuff that gets drawn on top of it in DrawStuff() does not appear.


Anybody has an idea?


 

Monsieur OUXX

Ok I think that the issue rests with : sprite = DynamicSprite.CreateFromExistingSprite(_renderingGui.BackgroundGraphic);

Because of that, AGS creates a very small sprite (because th eoriginal background image is tiny), and then no matter what I draw, it's always outside the surface, so I don't see it.
My complteley transparent sprite was much bigger, so I could see what was drawn into its surface.

I'll replace the line with sprite = DynamicSprite.Create(_renderingGui.Width,  _renderingGui.Height);


Solved.
 

SMF spam blocked by CleanTalk