(Formerly known as LoadImageFile, which is now obsolete)
static DynamicSprite* DynamicSprite.CreateFromFile(string filename)
Loads an external image FILENAME into memory as a sprite.
Returns the DynamicSprite instance representing the sprite, or null if the image
could not be loaded (file not found or unsupported format).
Only BMP and PCX files can be loaded with this command.
Use the Graphic property of the DynamicSprite to
interface with other commands and to use the new sprite in the game.
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.CreateFromFile("CustomAvatar.bmp");
if (sprite != null) {
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(100, 80, sprite.Graphic);
surface.Release();
sprite.Delete();
}
will load the file "CustomAvatar.bmp" and if successful draw the image near the middle
of the screen.
Once the image is finished with, Delete should be called on it.
See Also: DynamicSprite.Delete,
DynamicSprite.CreateFromSaveGame
|