Dynamic Sprites [SOLVED]

Started by Cogliostro, Wed 18/04/2012 01:50:27

Previous topic - Next topic

Cogliostro

Okay, I thought I'd be clever and post the version of the game I'm developing onto an object.

function room_AfterFadeIn()
{
// VERSION # posted to blank graphic # 105
   DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(object[8].Graphic);
   sprite.Resize(130, 100);
   DrawingSurface *surface = sprite.GetDrawingSurface();
   surface.DrawingColor = 15;
   surface.DrawStringWrapped(20, 40, 100, eFontTimes12pt, eAlignCentre, "Version  1.0.0");
   object[8].Graphic = sprite.Graphic;
   //surface.Release();
   //sprite.Delete();
}

It works until the function completes, then the Sprite & Surface release and delete and the version number turns into a blue cup.  This happens whether the last two lines are commented out or not.

So my question is this:  If you create a dynamic sprite and change it, how can you create a copy of that image that will last as long as the player is in the room?

- Cogliostro

P.S.  At this point I've invested about 30 times as much effort as it would take to just manually create a new version graphic, but I'm trying to push my programming limits.



EDIT

Two hours of frustration disappear the moment I focus enough to post the question.  For those who are curious,  declare the variables for the drawing surface and dynamic sprite at the beginning of the room script, outside of any of the room functions.  Then delete & release them in the room_Leave() function.
"First things first, but not necessarily in that order." - Dr. Who

Khris

Just a small note: declaring just the DynamicSprite outside the function is enough.

SMF spam blocked by CleanTalk