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) { RawDrawImage(100, 80, sprite.Graphic); 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
static DynamicSprite* DynamicSprite.CreateFromSaveGame (int saveSlot, int width, int height)Loads the screenshot for save game SAVESLOT into memory, resizing it to WIDTH x HEIGHT.
Returns the DynamicSprite instance of the image if successful, or returns null if the screenshot could not be loaded (perhaps the save game didn't include one).
In order for this to work, the "Save screenshots in save games" option must be ticked in the main Game Settings pane.
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:
// at top of script, outside interactions DynamicSprite *buttonSprite; // inside an interaction buttonSprite = DynamicSprite.CreateFromSaveGame(1, 50, 50); if (buttonSprite != null) { btnScrnshot.NormalGraphic = buttonSprite.Graphic; }will load the screenshot for save game 1 and resize it to 50x50. It then places it onto the btnScrnshot GUI button.
Once the GUI is disposed of, Delete should be called on the sprite.
See Also: DynamicSprite.Delete, GetSaveSlotDescription, DynamicSprite.CreateFromFile, DynamicSprite.CreateFromScreenShot
static DynamicSprite* DynamicSprite.CreateFromScreenShot (optional int width, optional int height)Creates a new DynamicSprite instance with a copy of the current screen in it, resized to WIDTH x HEIGHT. If you do not supply the width or height, then a full screen sized sprite will be created.
This command can be useful if you're creating a save game screenshots GUI, in order to display the current game position as well as the saved slot positions.
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:
// at top of script, outside interactions DynamicSprite *buttonSprite; // inside an interaction buttonSprite = DynamicSprite.CreateFromScreenShot(80, 50); if (buttonSprite != null) { btnScrnshot.NormalGraphic = buttonSprite.Graphic; }places a screen grab of the current game session onto btnScrnshot.
Once the GUI is disposed of, Delete should be called on the sprite.
See Also: DynamicSprite.Delete, GetSaveSlotDescription, DynamicSprite.CreateFromFile, DynamicSprite.CreateFromSaveGame
DynamicSprite.Delete();Deletes the specified dynamic sprite from memory. Use this when you are no longer displaying the sprite and it can be safely disposed of.
You do not normally need to delete sprites, since the AGS Sprite Cache manages loading and deleting sprites automatically.
However, when an extra sprite has been loaded into the game (for example, with the CreateFromFile or CreateFromScreenShot commands) then AGS does not delete it automatically, and you must call this command instead.
Example:
DynamicSprite* sprite = DynamicSprite.CreateFromFile("CustomAvatar.bmp"); object[1].Graphic = sprite.Graphic; Wait(200); object[1].Graphic = 22; sprite.Delete();will load the file "CustomAvatar.bmp", change Object 1 to display this graphic, wait 5 seconds, then change object 1 back to its old sprite 22 and free the new image.
See Also: DynamicSprite.CreateFromScreenShot, DynamicSprite.Graphic
readonly int DynamicSprite.Graphic;Gets the sprite slot number in which this dynamic sprite is stored. This value can then be passed to other functions and properties, such as Button.NormalGraphic.
Example:
DynamicSprite* ds = DynamicSprite.CreateFromScreenShot(50, 50); RawDrawImage(100, 100, ds.Graphic); ds.Delete();takes a screen shot, and draws it onto the background scene at (100,100).
See Also: DynamicSprite.CreateFromScreenShot, DynamicSprite.Delete
Browser Based Help. Published by chm2web software. |