Animated Sprites

Blitz3D Forums/Blitz3D Beginners Area/Animated Sprites

earok - the source code file "update3dentities.bb" has this bit in it:

The lines which work out a value for variable "NewDirn" establish which row (1-8) of the texture to use based on the camera orientation relative to the billboard model.

The line "correctframe=..." is where I set the appropriate texture frame to use.

The function "animatequad" uses my old single surface quad system to set the uv coordinates of the sprite based on the value of "correctframe". I wouldn't worry too much about the "animatequad" function - it is in the "Latestquadfuncs.bb" file.

If you are using blitz sprites then the only calculations you need are upto the point where 'correctframe' is calculated and then you can pass this directly to the entitytexture command as the 'frame' parameter.


In update3dentities.bb I calculate the value for "camdirn" and use that further down as you will see

CamAngle=EntityYaw(Camera,True) Mod 360
If CamAngle<0 Then CamAngle=CamAngle+360
CamDirn=(315-CamAngle)/45



	If Unit(k)\Billboard Then 
				If Unit(k)\QuadID<>-1 Then 
				;Animate the Quad appropriately..
					NewDirn=7+Unit(k)\Direction-CamDirn
					If NewDirn>8 Then NewDirn=NewDirn-8
					If NewDirn<0 Then NewDirn=NewDirn+8
					If NewDirn=0 Then NewDirn=8
					CorrectFrame=(Unit(k)\CurrentFrame-1)+(NewDirn-1)*8
				
				;If InCameraView(Unit(k)\X,Unit(k)\Y,Unit(k)\Z,Camera) And if Unit(k)\Billboard=1 Then AnimateQuad(Unit(k)\QuadID,1,1,8,8,CorrectFrame)
					If Combatant(Unit(k)\Category)\Animated Then AnimateQuad(Unit(k)\QuadID,1,1,8,8,CorrectFrame)
				;Billboard will be set to 1 for animated sprites, and to 2 for static objects like barbed wire.
				;CurrentFrame-1 as the Calculate Action uses a system which begins at 1 and ends at 
				;the maximum number of frames, while the quad functions have 0 as the first frame.
				;
				;
				
				
				;Position quad and face the camera....
					InitialQuadPosition(Unit(k)\QuadID,Unit(k)\X,Unit(k)\Y+OffsetY,Unit(k)\Z,0)
				
				
					PointAndCentre(Unit(k)\QuadID,EntityYaw(Camera,True))
					PositionQuadCentred(Unit(k)\QuadId)