Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Thu 10/06/2010 13:34:25

Title: [SOLVED]Making drawingsurface dynamicsprites appear on the GUI...
Post by: Technocrat on Thu 10/06/2010 13:34:25
Thanks to a mixture of cargo-cult programming and fluke, I've been able to use the drawingsurface to create the backdrop of my rooms out of tiles. Ok, so far so good, but I'm also looking to make a radarmap for Operation: Forklift. I've figured out what's needed to draw it, but the problem is that when it's drawn, it appears underneath units as the screen moves around.

In another thread, I've seen people saying it's possible to use drawingsurface to make dynamicsprites appear on the GUI. What do I need to do to make the sprite appear here, rather than on the background?
Title: Re: Making drawingsurface dynamicsprites appear on the GUI...
Post by: abstauber on Thu 10/06/2010 14:22:11
Oh, that's easy. You can either draw on a button or on the GUI background itself.

Here's an example to do it without buttons:


  sprForeground = DynamicSprite.Create(System.ScreenWidth, System.ScreenHeight, true);

  gForeground.BackgroundGraphic = sprForeground.Graphic;



Now you can draw on that surface as long as you like


DrawingSurface *surface = sprForeground.GetDrawingSurface();

surface.DrawImage(.........);
surface.Release();


Just keep in mind that you must not delete the sprite as long as it's assigned to the GUI Background.


edit: typo in the second code block
Title: Re: Making drawingsurface dynamicsprites appear on the GUI...
Post by: Technocrat on Sat 12/06/2010 04:32:16
Ok, I think I grasp the theory behind it, but as soon as I put in anything about it using sprForeground as the background graphic for "gRadar", I don't get the white rectangle I expect. Instead, it runs a very fast looping animation through all of the sprites in the game. Here is a portion of exactly what I'm using, in the room script. What is it I'm missing/doing wrong?


// Stuff for RadarMap Nonsense

  DynamicSprite* sprForeground = DynamicSprite.Create(42, 42, true);
  DrawingSurface *surface = sprForeground.GetDrawingSurface();

surface.DrawingColor=65535;
surface.DrawRectangle(0, 0, 42, 42);

  surface.Release();

  gRadar.BackgroundGraphic = sprForeground.Graphic;

Title: Re: Making drawingsurface dynamicsprites appear on the GUI...
Post by: Khris on Sat 12/06/2010 17:08:57
Declare the DynamicSprite outside the function (otherwise it is destroyed at the end of the function).
Title: Re: Making drawingsurface dynamicsprites appear on the GUI...
Post by: Technocrat on Sun 13/06/2010 06:36:26
Ah, brilliant - it's working perfectly now!

Merci muchly!