Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Intangible on Wed 22/02/2012 13:44:23

Title: Draw string - best practices
Post by: Intangible on Wed 22/02/2012 13:44:23
The help file is clear enough on how to draw a string to the background, but I'm not as sure about how to "change" the message I've written out. I'd need a way to erase the previous text, but Clear() actually wipes out the drawing surface (room background image and all). Is there a good tutorial somewhere on how to do this? If I could just see some simple, working examples in action I'd probably get it...
Title: Re: Draw string - best practices
Post by: Khris on Wed 22/02/2012 13:52:11
You need to make a backup of the room background before drawing to it.

// top of room script

DynamicSprite*backup;

// in room_Load

  backup = DynamicSprite.CreateFromBackground();


Now you can draw backup to the room's background to "clear" it before drawing the changed message on top.
Title: Re: Draw string - best practices
Post by: Intangible on Wed 22/02/2012 23:00:44
The approach makes sense, but can't figure out how to draw the dynamic sprite... the closest match I can find is "DrawSurface", which doesn't seem to accept a DynamicSprite:

count = count  +1;
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawSurface(backup); // compile error here; can't use DynamicSprite
surface.DrawingColor = 14;
surface.DrawString(0, 100, Game.NormalFont, String.Format("Test %d", count));
surface.Release();


Also, while I was trying to find a method that would work, I came across this in the help file:
DrawingSurface *mainBackground = Room.GetDrawingSurfaceForBackground(0);
DrawingSurface *nightBackground = Room.GetDrawingSurfaceForBackground(1);
mainBackground.DrawSurface(nightBackground, 50);
mainBackground.Release();
nightBackground.Release();

Would this approach allow me to accomplish the same thing, albiet with surface.DrawSurface? If so, is there an advantage to using the DynamicSprite approach vs. the DrawingSurface approach, or vice versa?
Title: Re: Draw string - best practices
Post by: Khris on Thu 23/02/2012 01:43:23
A DrawingSurface is only a middleman you need to change an existing image, to make an actual backup as in store image data, you need a DynamicSprite.
For DrawingSurface.DrawSurface(a) to work, a must be the DrawingSurface of an actual sprite, so it's really just a shortcut.

The command you're looking for is:

 surface.DrawImage(0, 0, backup.Graphic);
Title: Re: Draw string - best practices
Post by: Intangible on Thu 23/02/2012 03:34:37
Ah, that worked quite nicely. Thanks again!