Draw string - best practices

Started by Intangible, Wed 22/02/2012 13:44:23

Previous topic - Next topic

Intangible

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...

Khris

You need to make a backup of the room background before drawing to it.

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

Intangible

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?

Khris

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:

Code: ags
  surface.DrawImage(0, 0, backup.Graphic);

Intangible

Ah, that worked quite nicely. Thanks again!

SMF spam blocked by CleanTalk