Reference Manual - Table of Contents

Execution Control
Forms and Windows
Controls
Menus
System and Desktop
Graphic Drawing Commands

Animation
QuickTime Movies
Speech
Sound
File I/O
Printing
Serial Ports

Math Functions
String Functions
Date and Time
Memory Buffers
Error Handling
Console Text Window

Events

Direct Memory Access
Direct Mouse Access
Direct Keyboard Access
Code Resource Modules

A - Runtime Error Messages
B - Compiler Error Messages

 

 

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 spriteGfxID

Function 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, we’ll 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, you’ll 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.

 

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.

SpriteDone

Use command to finish an animation frame drawing sequence.

 

SpriteDisplay spriteGfxID

This command will copy the designated background frame buffer to the window.

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.

 

SpriteUnload spriteGfxID

This command will unload a sprite image buffer, freeing the memory used by it.

SpriteDup spriteGfxID1 ,spriteGfxID2

This command will instruct the Visual MacStandardBasic sprite graphic engine duplicate the contents of one sprite graphic to another quickly.

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.

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.

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.

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.

SpriteClear spriteGfxID

This command will erase the contents fill the frame buffer or sprite image.

var = SpriteWidth( spriteGfxID )

This function will return a numeric value which represents the width, in pixels, of sprite image designated by spriteGfxID.

 

var = SpriteHeight( spriteGfxID )

This function will return a numeric value which represents the height, in pixels, of sprite image designated by spriteGfxID.

 

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.