DynamicSprite.CreateFromScreenshot catches GUI before it's turned off

Started by monkey0506, Thu 16/04/2009 06:33:36

Previous topic - Next topic

monkey0506

Perhaps I'm being a bit daft, but I was wanting to do something such as this:

Code: ags
gMygui.Visible = false;
DynamicSprite *sprite = DynamicSprite.CreateFromScreenshot();
gMygui.BackgroundGraphic = sprite.Graphic;
gMygui.Visible = true;


That's a highly simplified version of what I'm actually doing but you get the basic idea. The problem is that the screenshot is being captured before the screen is refreshed to reflect the fact that the GUI was just turned off. Instead I'm having to work around it like this:

Code: ags
DynamicSprite *sprite = DynamicSprite.CreateFromBackground();
DrawingSurface *surface = sprite.GetDrawingSurface();
int i = 0;
while ((i < Game.CharacterCount) || (i < Room.ObjectCount)) {
  if (i < Game.CharacterCount) {
    if (character[i].Room == player.Room) {
      ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
      int w = ((Game.SpriteWidth[frame.Graphic] * character[i].Scaling) / 100);
      int h = ((Game.SpriteHeight[frame.Graphic] * character[i].Scaling) / 100);
      surface.DrawImage(character[i].x - (w / 2), character[i].y - h, frame.Graphic, 0, w, h);
    }
  }
  if (i < Room.ObjectCount) {
    if (object[i].Visible) {
      int graphic = object[i].Graphic;
      if (object[i].View) { // I'm not 100% sure, does Object.Graphic already reflect this anyway?
        ViewFrame *frame = Game.GetViewFrame(object[i].View, object[i].Loop, object[i].Frame);
        graphic = frame.Graphic;
      }
      int w = Game.SpriteWidth[graphic];
      int h = Game.SpriteHeight[graphic];
      if (!object[i].IgnoreScaling) {
        int scale = GetScalingAt(object[i].X, object[i].Y);
        w = ((w * scale) / 100);
        h = ((h * scale) / 100);
      }
      surface.DrawImage(object[i].X, object[i].Y - Game.SpriteHeight[graphic], graphic);
    }
  }
  i++;
}
surface.Release();


Clearly a lot more work to try and achieve the same effect. However, I cannot use Wait in order to let the screen update. Short of that is there any other way to prevent the GUI from being seen in the captured screenshot?

RickJ

Create a linear state machine to execute the sequence in repeatedlf_execute()
Code: ags

int state=0;
DynamicSprite *sprite;

function CaptureBackground() {
   state = 1;
}

function repeatedly_execute() {

     // Capture Background
     if (state==1) {
          gMygui.Visible = false;
          state++;
     }
     else if (state==2) {
          DynamicSprite *sprite = DynamicSprite.CreateFromScreenshot();
          gMygui.BackgroundGraphic = sprite.Graphic;
          state++;
     }
     else if (state==3) {
          gMygui.Visible = true;
          state++;
     }
}

monkey0506

I actually need to update the sprite every game loop, so unfortunately that wouldn't work either. That's actually precisely the reason I can't just use Wait(1) is because I'm updating this particular effect every game loop.

I'm still getting 40 FPS when I run the debugger though so it may be a mute point anyway, I was just looking to optimize it however possible.

SMF spam blocked by CleanTalk