I've started trying to learn the drawing commands in AGS and I'm getting a bit stuck. What I'm trying to do at the moment is permanently change an object/button/GUI/whatever's sprite. What I have so far is...
// room script file
function room_AfterFadeIn()
{
DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(2, true);
DrawingSurface *surface = sprite.GetDrawingSurface();
surface.DrawingColor = 14;
surface.DrawPixel(1, 1);
surface.Release();
oObject1.Graphic = sprite.Graphic;
Display("Click to continue");
}
Which is more or less copied out of the manual. This works fine up to the Display part, then the object's sprite is deleted. Presumably this is because the sprite pointer is unloaded and so the sprite is lost, so I'd need to make the pointer global. Question 1: how do I import the sprite and surface pointers into a local script (i.e. what varaible types should I use?)
Also, I don't really know what I'm doing with the drawing functions, so is this the right way to go about it?
And yeah, I know I should call sprite.Delete() when I've finished with it.
Try this:
DynamicSprite *sprite;
function room_AfterFadeIn()
{
sprite = DynamicSprite.CreateFromExistingSprite(2, true);
DrawingSurface *surface = sprite.GetDrawingSurface();
surface.DrawingColor = 14;
surface.DrawPixel(1, 1);
surface.Release();
oObject1.Graphic = sprite.Graphic;
Display("Click to continue");
}
as soon as the function finishes, the sprite variable WAS going out of scope, which automatically deletes the sprite. Basically, any Dynamic Sprites you want to keep must be declared outside of any function.
Thanks, that makes sense. Am I right in guessing that you have to do all drawing functions either in the global script or in a room script then, with no way to export dynamic sprites?
You can export them, same as any other variable. They can go in modules, too.
Okay, so if I declare
DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(2, true);
at the top of my global script, stick
export sprite;
at the bottom, how do I import it into my room file?
import sprite;
wants a variable type.
You can't run the create function at the declaration if it is outside a function. so:
// Global script (or module):
DynamicSprite *sprite;
export sprite;
//Global script (or module) in side some function:
function whatever() {
sprite=DynamicSprite.CreateFromExistingSprite(2, true);
}
// Global header (or module header)
import DynamicSprite *sprite;
Ah brilliant. No doubt I'll be back on here when I get stuck with the next thing, but thanks for the help SSH