Reference Manual - Table of Contents
Animation Visual MacStandardBasic makes animation easy and this section describes the commands and functions that can be used to creating fast moving graphic animation on you Macintosh.
Command Summary:
SpriteFrame var, windowID
SpriteEnd
SpriteBegin FrameBufferID
SpriteDone
SpriteDisplay FrameBufferID
SpriteLoad var, ResID
SpriteUnload spriteGfxID
SpriteDup spriteGfxID1, spriteGfxID2
SpriteDraw spriteGfxID, x, y, priority
SpriteCopy spriteGfxID, x, y, priority
SpriteDrawSize spriteGfxID, x, y, widthOffset, heightOffset, priority
SpriteCopySize spriteGfxID, x, y, widthOffset, heightOffset, priority
SpriteClear FrameBufferID
SpriteClear spriteGfxIDFunction Summary:
var = SpriteWidth ( spriteGfxID )
var = SpriteHeight ( spriteGfxID )
var = SpriteHit ( spriteGfxID, minLayer#, maxLayer# )
Sprite Animation Introduction Sprite animation is a simple concept and commands in Visual MacStandardBasic automate most of the work for you. The word sprite is normally used to indicate a movable graphic image. You can create a background picture, through various methods, and then draw sprites onto background.
You could draw these images one at a time directly onto window but this usually results in a significant amount of flicker. We want smooth animation so another method is used. An offscreen graphic memory buffer is created that has the exact size and attributes of the window we want to do animation in. We draw the background and sprites in this offscreen graphic frame buffer first then quickly paste the entire contents of this frame buffer onto the window. The result is smooth animation with no flicker, which is what we want.
The following is a list of steps that is normally used when creating animation in Visual MacStandardBasic:
Create a window of desired size that will be used to display the animation. You can use the Window command to do this. You can instruct the Window command to create but not display the window until you use the ShowWindow command.
Create a offscreen frame buffer using the SpriteFrame command. You can create many offscreen frame buffers for the same window.
You should load the sprite graphic images using the SpriteLoad command. These images are PICT resources that can be created by other image editors and 3D rendering software.
Use the SpriteBegin command to instruct the MacStandardBasic sprite graphic engine that the sprite drawing commands that follow should use a particular offscreen graphic frame buffer.
You can use four commands to place sprites in the graphic frame buffer using x & y pixel coordinates: SpriteDraw, SpriteCopy, SpriteDrawSize, and SpriteCopySize. You can designate what layer that the sprite is placed on, well discuss layers a little later. See information later in this section to see how these commands are different in their usage.
Use the SpriteDone command to tell the MacStandardBasic sprite graphic engine that the current sprite drawing process is done. The sprite graphic engine will draw the sprites on their proper layers so that images overlap properly.
The SpriteDisplay command quickly replaces the current contents of the window with the offscreen graphic frame buffer.
Now you can change variables that might contain the x & y coordinates of your various sprites then return to Step 4.
This is really very simple. Once you see a few demonstration programs of MacStandardBasic animation, youll be amazed at the effects that can be create with just a few lines of MacStandardBasic.
Layers The MacStandardBasic sprite graphic engine supports 100 layers(plus background) that sprites can be drawn on. These layers allow you to draw the sprites in any order and still be correct in what sprite should overlap another. This means that a sprite will properly pass on top of one sprite while passing behind another according to their layer number.
Layer values are from 0 through 100, with 0 being the bottom layer (farthest back) and 100 being the topmost layer. Layer value 0 means that the sprite will be drawn first on the background with the layers 1 through 100 drawn on top.
SpriteFrame var, windowID
This function returns a numeric value representing a spriteGfxID. It is used to initialize sprite animation and establish a graphic frame buffer for the window. This command identifies a offscreen frame buffer that the MacStandardBasic sprite graphic engine uses for an offscreen window frame buffer. You can create many graphic frame buffers for the window.
var - This should be a numeric variable that will contain a value the should be used to reference the graphic frame buffer being created. This variable will equal a -1 if an error occurs.
windowID - This should be a Form name or a variable, used in the WINDOW command, that contains a value that is used to reference the window.
SpriteEnd
This command will deinitialize sprite animation and free all memory used by background graphic frame buffers and sprite objects.
SpriteBegin spriteGfxID
Use command to start an animation frame drawing sequence. This command will instruct the MacStandardBasic sprite graphic engine which frame buffer to be the active one.
spriteGfxID - This should be a numeric variable that will contain a value the should be used to reference a graphic frame buffer that was previously created. This is usually the variable used in the SpriteFrame command.
SpriteDone
Use command to finish an animation frame drawing sequence.
SpriteDisplay spriteGfxID
This command will copy the designated background frame buffer to the window.
spriteGfxID - This should be a numeric variable that will contain a value the should be used to reference a graphic frame buffer that was previously created. This is usually the variable used in the SpriteFrame command.
SpriteLoad var, ResID
This command will load a graphic picture (PICT resource) into a sprite image buffer. Use SpriteLoad to use PICT graphics resources for sprite graphics. After this command is executed, a numeric value is placed into var by the MacStandardBasic sprite graphic engine. Use this value to reference this sprite graphic image in commands such as: SpriteDraw, SpriteCopy, SpriteDrawSize, SpriteCopySize, and SpriteUnload.
var - This should be a numeric variable that will contain a value the should be used to reference the sprite graphic image. In other commands and functions this value is refered to as spriteGfxID. This variable will equal a -1 if an error occurs.
ResID - This should be a numeric expression that contains a value that is used to reference the PICT resource that contains the graphic image to be loaded.
SpriteUnload spriteGfxID
This command will unload a sprite image buffer, freeing the memory used by it.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image.
SpriteDup spriteGfxID1 ,spriteGfxID2
This command will instruct the Visual MacStandardBasic sprite graphic engine duplicate the contents of one sprite graphic to another quickly.
spriteGfxID1 - This should be a numeric value be used to reference the source sprite graphic image .
spriteGfxID2 - This should be a numeric value be used to reference the destination sprite graphic.
SpriteDraw spriteGfxID, x, y, layer
This command will instruct the MacStandardBasic sprite graphic engine to draw the sprite object at designated coordinates in the current graphic frame buffer. The SpriteDraw command uses a transparency mode, all white pixels will in the sprite will be ignored when drawing sprite image onto frame buffer.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image to be drawn.
x - This is a numeric expression designating the center x coordinate of the sprites bounding rectangle.
y - This is a numeric expression designating the center y coordinate of the sprites bounding rectangle.
layer - This should be a numeric value used to specify the layer to be used when drawing the sprite image.
SpriteCopy spriteGfxID, x, y, layer
This command will instruct the MacStandardBasic sprite graphic engine to draw all pixels of the sprite object at designated coordinates in the current graphic frame buffer.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image to be drawn.
x - This is a numeric expression designating the center x coordinate of the sprites bounding rectangle.
y - This is a numeric expression designating the center y coordinate of the sprites bounding rectangle.
layer - This should be a numeric value used to specify the layer to be used when drawing the sprite image.
SpriteDrawSize spriteGfxID, x, y, widthOffset, heightOffset, layer
This command will instruct the MacStandardBasic sprite graphic engine to scale and draw the sprite object at designated coordinates in the current graphic frame buffer. The SpriteDraw command uses a transparency mode, all white pixels will in the sprite will be ignored when drawing sprite image onto frame buffer.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image to be drawn.
x - This is a numeric expression designating the center x coordinate of the sprites bounding rectangle.
y - This is a numeric expression designating the center y coordinate of the sprites bounding rectangle.
width - This is a numeric expression designating the width in pixels when sprite will be resized and drawn in the frame buffer.
height - This is a numeric expression designating the height in pixels when sprite will be resized and drawn in the frame buffer.
layer - This should be a numeric value used to specify the layer to be used when drawing the sprite image.
SpriteCopySize spriteGfxID, x, y, widthOffset, heightOffset, layer
This command will instruct the MacStandardBasic sprite graphic engine to scale and draw all pixels of the sprite object at designated coordinates in the current graphic frame buffer.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image to be drawn.
x - This is a numeric expression designating the center x coordinate of the sprites bounding rectangle.
y - This is a numeric expression designating the center y coordinate of the sprites bounding rectangle.
width - This is a numeric expression designating the width in pixels when sprite will be resized and drawn in the frame buffer.
height - This is a numeric expression designating the height in pixels when sprite will be resized and drawn in the frame buffer.
layer - This should be a numeric value used to specify the layer to be used when drawing the sprite image.
SpriteClear spriteGfxID
This command will erase the contents fill the frame buffer or sprite image.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image.
var = SpriteWidth( spriteGfxID )
This function will return a numeric value which represents the width, in pixels, of sprite image designated by spriteGfxID.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image.
var = SpriteHeight( spriteGfxID )
This function will return a numeric value which represents the height, in pixels, of sprite image designated by spriteGfxID.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image.
var = SpriteHit ( spriteGfxID, minLayer#, maxLayer# )
The function returns a layer # to determine sprite collision detection. Use function will return a numeric value which represents whether a the sprite specified by spriteGfxID has overlapped (collision detection) a layer that was drawn on or between the layer numbers specified by minLayer# and maxLayer#.
A value of -1 is returned if no collision has occurred.
spriteGfxID - This should be a numeric value be used to reference the sprite graphic image.
minLayer# - This should be a numeric value used to specify the lowest layer # to be used when determining sprite collision detection.
maxLayer# - This should be a numeric value used to specify the highest layer # to be used when determining sprite collision detection.