How to display an overlay

Started by artium, Wed 05/09/2018 20:54:14

Previous topic - Next topic

artium

How is it possible to actually display the overlay on the screen?

Code: ags


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


  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.



dayowlron

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.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Khris

Declare the sprite and overlay outside your function.

Code: ags
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.

SMF spam blocked by CleanTalk