[SOLVED]Making drawingsurface dynamicsprites appear on the GUI...

Started by Technocrat, Thu 10/06/2010 13:34:25

Previous topic - Next topic

Technocrat

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?

abstauber

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:

Code: ags

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

  gForeground.BackgroundGraphic = sprForeground.Graphic;



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

Code: ags

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

Technocrat

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?

Code: ags

// 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;


Khris

Declare the DynamicSprite outside the function (otherwise it is destroyed at the end of the function).

Technocrat

Ah, brilliant - it's working perfectly now!

Merci muchly!

SMF spam blocked by CleanTalk