Jim Brown (Syntax Error) - config2000 ... hotmail.com
SpriteControl is a set of 26 commands / functions for
controlling Blitz3D quad sprites just like Blitz2D images.
Most of the commands mimic the Blitz2D image operations and share
the same name (with a '3D' extension).
This makes the functions easier to remember. I created the
SpriteControl functions for the following advantages:
Example:
Blitz2D
myimage=LoadImage("logo.bmp") ; load a 2d image
DrawImage myimage,10,20 ; draw the 2d image at pixel coordinates
10,20
SpriteControl
myimage=LoadImage3D("logo.bmp") ; create 3d sprite from
image (and scale to same size)
DrawImage3D mysprite,10,20 ; positions a sprite image at pixel
coordinates 10,20
A quick start guide to using SpriteControl:
1) Use Include "Sprite Conrol.bb"
at the top of your program
2) Initialise a 3D graphics display with SpiteGraphics3D
width,height
3) Load or create your sprites using LoadImage3D()
/ CreateImage3D() / Text3D()
and etc ...
4) Use DrawImage3D to position the sprites at 2D
pixel coordinates
5) Call RenderWorld / Flip / WaitKey
etc to display the sprites.
Here is a simple example:
Include "SpriteControl.bb"
SpriteGraphics3D 640,480
SetFont LoadFont("Tahoma",25,1)
mysprite=Text3D(100,200,"Hello World")
RenderWorld
Flip
WaitKey
End
NOTE
There is a streamlined version of SpriteControl
called 'Sprite Control BASIC.bb'
This include has bare minimum functionality for getting a sprite
quad on screen..
SpriteControl uses a pivot which is parented to a main camera.
All loaded/created sprites are attached to this pivot.
Before using SpriteControl you need to set up a display system
first. This can be done in two ways:
Mehod 1
Use the SpriteGraphics3D command
This is the quickest and easiest way to set up the display. The SpriteGraphics3D
command does everything for you .
After calling this command your display system is initialised.
You can now load/create sprites for displaying.
The global variables 'spritecamera' and 'spritepivot' hold the
handles of the camera and sprite pivot respectivelty.
Example:
Include "Sprite Control.bb" SpriteGraphics3D 640,480 sprite=LoadImage3D("brick.bmp") DrawImage3D sprite,50,70 RenderWorld : Flip : WaitKey : End |
Method 2
Use the Blitz3D Graphics3D and CreateCamera()
commands.
Now attach a sprite pivot to the camera with a call to the CreateSpritePivot()
function.
After that you may load/create your sprites.
Example:
Include "Sprite Control.bb" Graphcis3D 640,480 cam=CreateCamera() piv=CreateSpritePivot(cam) sprite=LoadImage3D("brick.bmp") DrawImage3D sprite,50,70 RenderWorld : Flip : WaitKey : End |
Draw Priorty
By default all loaded/created sprites have a draw priority of
-100
You can change the oder in which the sprites are drawn with the
Blitz3D EntityOrder command.
To place sprites in front of others use a lower value such as
-101, -200, -350 etc..
To place sprites behind others use a higher value such as -99,
-80, -40 etc..
Be careful not to bring to the priority up too high otherwise the
sprites will start to disappear behind other 3d objects on
screen.
Read up on the EntityOrder command for more
details.
Hiding/Showing the sprites
Once you create a sprite and position it on screen it is always
drawn (unlike the 2d version).
If you want to hide/show the sprite use the Blitz3D HideEntity
and ShowEntity commands:
piv=CreateSpritePivot()
sprite1=LoadImage3D("blah1.bmp")
sprite2=LoadImage3D("blah2.bmp")
sprite3=LoadImage3D("blah3.bmp")
HideEntity piv ; hide all attached sprites
ShowEntity piv ; show all attached sprites
Don't forget, once you have finished with the sprite use FreeImage3D to remove it from memory.
Zooming the main camera
If you plan on zooming the main camera then use the CameraZoom3D
camera,zoomratio# command.
This will not only zoom the specified camera but also the 'Sprite
Control' sprite pivot attached
The pivot needs to be re-positioned when the camera is zoomed
otherwise the sprites will not display correctly.
Note: You cannot zoom the camera below 1.0
Something else to be aware of. If you use frame tweening in your
game then you need to use the CameraZoom3D just
before CaptureWorld to prevent the sprites from
jumping into position. See the MAIN EXAMPLE.bb code and search
for CaptureWorld.
There are two global variables used in SpriteControl:
spritecamera - The handle of the camera created with SpriteGraphics3D
spritepivot - The handle of the pivot created with CreateSpritePivot()
I wish to thank the following people for their help, suggestions, and contributions made to SpriteControl:
skidracer - For the excellent 'pixel perfect'
routines.
Rob Cummings - For help on implementing the dual
camera method.
FredBorg - For contributing HandleImage and
CopyImage3D()
EricZann - For the suggestion to include a
function which changes text in an existing sprite. See Modify3D
Ghislain Schoofs - For the idea to give
LoadImage3D() and other such functions a 'parent' parameter.
BlitzSupport/Skully - MaskImage3D() function
(modified from LoadMaskedSprite in the Blitz code archives)
bot builder - The MidHandle3D function (modified
the Mid3DHandle function from the code archives)