Declare the DynamicSprite at the top of the script, outside the function like so:
Code: ags
And inside the function, just put:
Code: ags
Otherwise the DynamicSprite pointer will be deleted when the function finishes, and yes, your object will disappear (or in some cases become the default bluecup).
Edit: Also, if you haven't done so already, you may want to upgrade to AGS 3.0.2 when the final version comes out. With the new DynamicSprite.CreateFromDrawingSurface function, it shouldn't really be necessary to have two backgrounds, just make a temporary copy of the background in the EnterRoomBeforeFadein event.
DynamicSprite* sprite;
And inside the function, just put:
sprite = DynamicSprite.CreateFromExistingSprite(object[0].Graphic);
Otherwise the DynamicSprite pointer will be deleted when the function finishes, and yes, your object will disappear (or in some cases become the default bluecup).
Edit: Also, if you haven't done so already, you may want to upgrade to AGS 3.0.2 when the final version comes out. With the new DynamicSprite.CreateFromDrawingSurface function, it shouldn't really be necessary to have two backgrounds, just make a temporary copy of the background in the EnterRoomBeforeFadein event.