Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Charity on Mon 30/06/2008 22:03:00

Title: DrawSurface replacing RawRestoreScreen (SOLVED!)
Post by: Charity on Mon 30/06/2008 22:03:00
I'm trying to update a script to work with the new DrawingSurface functions, but I am having trouble getting the DrawSurface function to work.

I made a function that, among other things, draws an oval on the screen and a second function that, among other things, is supposed to take the oval away.  Previously, I could simply use RawSaveScreen at some point before the oval was drawn and then RawRestoreScreen in the second function to take it away, but I'm having trouble duplicating the effect.

At the top of the script I have:
DrawingSurface *screenBackup;

Then in the oval creation function:
  screenBackup = Room.GetDrawingSurfaceForBackground();
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  surface.DrawingColor=31;
  surface.DrawEllipse(AnchorX, AnchorY, RangeX, RangeY);
  surface.Release();


And in the later function:
    DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
    surface.DrawSurface(screenBackup);
    surface.Release();
    screenBackup.Release();


As far as I can tell, this should produce the desired result, but instead, when I call the second function the game crashes and I get the error:
Error: DrawingSurface.DrawSurface: cannot draw surface onto itself

What am I doing wrong?
Title: Re: DrawSurface replacing RawRestoreScreen
Post by: Khris on Tue 01/07/2008 00:32:42
It's supposed to be:

// backup
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  screenBackup = surface.CreateCopy();

// restore
    DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
    surface.DrawSurface(screenBackup);
    surface.Release();


.CreateCopy() must be used in order to create a second DrawingSurface object in memory; otherwise there's two pointers both pointing to the same surface. That's why you received the error.
Title: Re: DrawSurface replacing RawRestoreScreen
Post by: Charity on Tue 01/07/2008 06:41:10
Thanks!  Works like a charm.