static DynamicSprite* DynamicSprite.CreateFromExistingSprite(
int slot, optional bool preserveAlphaChannel)
Creates a new dynamic sprite containing a copy of the specified sprite slot.
Returns the DynamicSprite instance representing the new sprite. This function
is useful as it effectively allows you to apply transformations such as resizing to
any sprite in the game.
Use the Graphic property of the DynamicSprite to
interface with other commands and to use the new sprite in the game.
preserveAlphaChannel determines whether the sprite's alpha channel will also
be copied across. It is false by default for backwards compatibility reasons, and
is useful because it allows you to strip the alpha channel in order to do whole image
transparency. This parameter has no effect with sprites that do not have an alpha
channel.
IMPORTANT: This command loads an extra sprite into memory which is not controlled
by the normal AGS sprite cache and will not be automatically disposed of. Therefore, when
you are finished with the image you MUST call Delete on it to free its memory.
IMPORTANT: If the DynamicSprite instance is released from memory (ie. there is
no longer a DynamicSprite* variable pointing to it), then the sprite will also be
removed from memory. Make sure that you keep a global variable pointer to the sprite
until you are finished with it, and at that point call Delete.
Example:
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(object[0].Graphic);
sprite.Resize(20, 20);
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(100, 80, sprite.Graphic);
surface.Release();
sprite.Delete();
creates a copy of object 0's current sprite, resizes it down to 20x20, and then draws
the result onto the background.
See Also: DynamicSprite.Delete,
DynamicSprite.Resize
|