DrawSurface replacing RawRestoreScreen (SOLVED!)

Started by Charity, Mon 30/06/2008 22:03:00

Previous topic - Next topic

Charity

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:
Code: ags
DrawingSurface *screenBackup;


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


And in the later function:
Code: ags
    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:
Code: ags
Error: DrawingSurface.DrawSurface: cannot draw surface onto itself


What am I doing wrong?

Khris

#1
It's supposed to be:

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

Charity


SMF spam blocked by CleanTalk