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?
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.
Thanks! Works like a charm.