Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: artium on Wed 05/09/2018 20:54:14

Title: How to display an overlay
Post by: artium on Wed 05/09/2018 20:54:14
How is it possible to actually display the overlay on the screen?

Code (ags) Select


function Bubble::Render(int x, int y)
{
  int radius = 10;
 
  DynamicSprite* sprite = DynamicSprite.Create(radius, radius, true);
  DrawingSurface* surface = sprite.GetDrawingSurface();

  surface.DrawingColor = 100;
  surface.DrawCircle(radius, radius, radius); 
  surface.Release();

  Overlay* myOverlay = Overlay.CreateGraphical(x, y,  sprite.Graphic,   false);

  // what now? 
 
  sprite.Delete();
}



The only way I found that worked displaying a dynamic sprite on the screen was to draw on the "Room.GetDrawingSurfaceForBackground()" surface:
Code (ags) Select


  DrawingSurface *roomSurface = Room.GetDrawingSurfaceForBackground();
  roomSurface.DrawImage(x, y, sprite.Graphic);
  roomSurface.Release();


But the problem with this approach is that it is not possible to delete the sprite afterwards.

The goal is to create random bubbles that will slowly raise to the to the top of the screen.
The creation process of the bubbles should be dynamic.


Title: Re: How to display an overlay
Post by: dayowlron on Thu 06/09/2018 03:42:39
I could be totally wrong, but the Overlay.CreateGraphical draws the sprite at the x,y coordinates, but then you immediately delete the sprite which would cause the Overlay to not have a sprite to draw anymore.
Put a "wait" call where you have "// what now?" and see if the sprite shows up. If so then you will have to save the sprite to get it to work.
Title: Re: How to display an overlay
Post by: Khris on Thu 06/09/2018 11:44:37
Declare the sprite and overlay outside your function.

DynamicSprite* sprite;
Overlay* myOverlay;

function Bubble::Render(int x, int y)
{
  int radius = 10;
 
  sprite = DynamicSprite.Create(radius, radius, true);
  // ...


Like dayowlron says, all variables / Pointers declared inside a function don't survive it ending.