List of the functions in my sprite system

BlitzMax Forums/BlitzMax Programming/List of the functions in my sprite system

sswift(Posted 2007) [#1]
This is the code to my sprite system, minus all the stuff inside the various functions and methods.

If you've been thinking about purchasing the system, this should give you a real good idea of the functionality the system provides, how easy it is to understand, and how well commented it is.
(Not included here are all the functions from a font system I will provide upon request which utilizes the system to allow for animated text objects.)

[edit]
I have to post it in two seperate parts, it's apparently too long for a single post.
[/edit]


sswift(Posted 2007) [#2]
Rem


	Swift Sprite System for BlitzMAX - Copyright 2006 Shawn C. Swift


	Sprites:

		The Basics:
		
			Create sprites with the Sprite.Create() function.
			Position sprites with the SetPostion() method.
			Call Sprite.DrawAll() once per frame to draw the sprites.
			Use the Overlaps() method to determine if one sprite is touching another.
		

		Additional notes:

			- If you are using MaxGUI, you should set your canvas before you do anything else, like SetBlend(). 
			  Otherwise, you'll get an error about trying to access a null object!
			

			- It is reccomended you set AutoMidHandle() before loading your sprite images.  
		
			  This is because rotation with scaling does not work as you might expect in BlitzMax.  If the handle of an image is not in its center, 
			  and you flip the image on one or both axis by setting the scale to -1, then the image will no longer rotate around its center.  Using 
			  AutoMidHandle() allows you to both rotate and flip sprites.
		 
				
			- It is also reccomended you use SetBlend() to set the blending mode to ALPHABLEND before you create the sprites.  
		
			  This is because you cannot render sprites with alpha or set the alpha transparency unless the sprites are drawn with ALPHABLEND, and the 
			  sprites' own blending modes will default to whichever blending mode you have set when they are created.
			
		
			- You can parent one sprite to another.  When you move the parent, the children will move with it!  
		  
			  These propertes of the parent are carried over to the children:  
			  Position, Scale, Rotation, Alpha, Viewport
					

			- Because BlitzMax does not allow images to be scaled on an arbitrary axis, scaling a parent non-uniformly may have unexpected results if the 
			  children are rotated relative to the parent.  For example, if the children are rotated 90 degrees relative to the parent, and the parent is 
			  stretched vertically, the children will stretch vertically as well, but vertical for them is now sideways, so they'll get "wider" instead!
  		  
			  This is only an issue when a parent is stretched on one axis more than the other, and the children are rotated relative to it, so you are
			  unlikely to encounter this when using the system, but if you do, just be aware it isn't a bug.

	
	Animation:

		The basics:
						
			- Call the animation functions to add animations to the animation queue.
			- Call the animation.update() function to trigger animations and move the sprites.
		
		
		Additional notes:																
																																																		
			- Nearly all sprite properties can be animated.
			- One animation per property can be active at a time.  
			- If a property is being animated, and a new animation of that property triggers, the old animation will stop and the new one will begin.


			- Using TriggerDelay, you may prevent an animation from triggering immediately.  This allows you to play several animations in a row, even if 
			  they are to animate the same sprite property.


			- "StartAge" is the age the sprite will be set to when it is first triggered. 

			  StartAge is useful for making objects move in a sine wave.  You don't want all the objects to start at the same location, but positioning 
			  each differently at the start won't achieve the desired result.  With StartAge you can position them along a straight line, and then increase 
			  the age each starts at as you move along the line.  Then they will each start at a different point in their sine wave animation.
				
												
		Examples:
		
			Animate.PositionX(Ship, 100, 200, 1000, ANIM_LOOP|ANIM_PINGPONG)
		
	
	Tips and tricks:
	
		- If you have two sprites in different spaces, and you want to position one sprite over the other, do TFormPoint(0, 0, FirstSprite, SecondSprite)
		  to transform the center of the first sprite from the first sprite's space, to the space of the second sprite.  This is much simpler than the
	  	  alternative, which would be TFormPoint(FirstSprite.X#(), FirstSprite.Y#(), FirstSprite.Parent(), SecondSprite)!
				

 	Ideas:

		Add ability to have a function be called when two sprites collide, automatically?  Will this allow me to combine sprite and animation calls into one?

		Function to free animating children of a sprite?

		Is blurring shadows feasable?  Perhaps.  Need a way to specify it in pixel radius though.    				

		Physics:
		Create a physics system for sprites.  Support ground friction, max speed, thrust, wind vector, gravity.  Collisions?  Mass?
		

	Updates:
		

		v37:
		
			- Freeing a sprite now stops its animation, and frees all of its children.  This allows you to free all sprites attached to a menu for example.
			  There is now no need to call Animate.Stop() for a sprite you want to free before you free it. 
		

		v36:
					
			- You may now animate scale and rotation.
		
			- A child's order is now relative to any parents it has.  A negative order for a child will cause it to render behind the parent.
		
			- You may now set flags for children to allow them to retain their position, scale, rotation, alpha, order, and visibility state, 
			  instead of said settings being affected by those of the parent.


		v48:
		
			- You may now set each sprite color channel to a value up to 255*2.  This will double the brightness of the sprite via LIGHTBLEND.
			  See Sprite.SetColor() for more details.
			
			- You may now cast shadows from sprites!  See Sprite.SetShadow() for details. 
			
			- There are now three point/vector transform functions.  Sprite.TFormPoint, Sprite.TFormVector, and Sprite.TFormNormal.  These are 2D versions
			  of the transform functions in Blitz 3D.  If you've used those, you know how useful they are!  These allow you to transform stuff from the space
			  of one sprite, to another, or to and from global space.


		v66:
		
			- You may now name sprites!
			

		v83:
		
			- SetPositionX and SetPositionY are now SetX and SetY.
			- Many of the animation functions must now be accessed like so:  SpriteName.AnimatePosition()
			

		v84:
		
			- Added BufferImages() function, which enables you to avoid the choppiness that results from images not being buffered in video ram.
			

		v85:
		
			- Fixed bug where it was possible to set a a frame outside the valid image frames, which would cause a crash. 
			  Frame() now has a Clamp parameter, which clamps the returned frame to the valid range.  This way you can still set and get frames outside the
			  valid range but get the nearest clamped frame if you need it.
			

		v86:
			
			- Children are now affected by the color of the parent!  This means you can now fade in a menu simply by fading the color of the background if
			  all the menu items are children of that background!  In addition the RETAIN_COLOR flag is now available to override this behavior.
			

		v87:
		
			- The FreeSprite parameter on the animation functions, which formerly was found between TriggerDelay and StartAge, is no more!
			  To free a sprite from now on, use the new MODE_FREE flag.
			
			- You can now hide a sprite when an animation completes using the MODE_HIDE flag!
			

		v88:
		
			- Fixed a missing type specifier on new mode flags.
			
			- Added commands X1() thru Y4() to find sprite corners.  Takes into account image size, scale, and rotation, and can return points in parent or
			  global space.  (UPDATE: These commands do not currently work properly.  Do not use them!)
			
			- Fixed new child sprite color relative to parent color functionality. 	
			

		v89:
			
			- Added GLOW_SOLID sprite flag which enables a new glow method.  See below for details.  	
			

		v90:
		
			- Added MODE_SHOW which allows you to show a sprite when an animation truly begins, namely, when TriggerDelay elapses.
			
			- Added RELATIVE_VIEWPORT flag.  This allows viewports which are relative to a sprite's parent. 
			  The parent's position and scale will affect a viewport, but its rotation will not.  
			

		v91:
		
			- Fixed bug with MODE_PINGPONG looping forever even when MODE_LOOP is not specified.

			
		v92:
		
			- SetScale now takes only a single scale parameter.  If you wish to scale the two axes differently, then use SetScale2.


		v93:
		
			- Added function Animate.Animating().  This function allows you to specify a sprite name, and if any sprites with that name are animating,
			  it will return true.  You may optionally specify the type of animation, and by omitting a name, you may check ALL sprites.
		
			
		v94:
		
			- Fixed bug in animation system.  When an animation completes, sprites are now guaranteed to have the specified end value from the animation.
			
			- Added ability to do things like SetPosition(0, 0, 10, 10, 0, 0, 1000) with a time of 0 to simply position the sprite at the specified end
			  position after one second.  The start value does not matter when using a time of 0.
			
			- Added function Sprite.FreeByName() which allows you to free all sprites with a specific name!
		
		
		v95:
	
			- Removed UpdateAll() from Animate.Create().  I am not certain this will not cause any issues with sprite images not appearing or collision 
			  testing immediately after an image change, so if you encounter problems where there were none before, let me know!  This change speeds up the
			  creation of new animations, so if you create 2000 of them at once, it won't bog down.
		
		
		v96:
		
			- Added SpriteName.FreeChildren() method.  This method frees all the children of a sprite, but not the sprite itself.


		v97:
		
			- Updated Path.FindNearestPoint() to exit quikly with an endpoint if the specified point lies outside the path.
			
			- Updated Path.Transform() so it uses Path.FindNearestPoint() to find the closest point to the specified X position, instead of the old method
			  which I forgot to update that just naively stepped through every point in the path until the distance was too great.  
			
			  This new method should be much much faster for paths with hundreds of points that have lots of sprites on them!
			
			- Fixed bug in BufferImages().  BufferImages() would crash if any sprites had no image.


		v98:
			
			- Added MODE_SPEEDUP_EXP and MODE_SLOWDOWN_EXP flags which allow you to animate acceleration and deceleration with an expoential change instead
			  of one which is cosine based.  Use this for snappier menu transitions, or to make text stay opaque for a longer period then fade out suddenly.
			
			- Added Animate.TweenExponential#() which makes the above work.
			
			- Added Animate.SetExponent() which allows you to set the exponent used for MODE_SPEEDUP_EXP and MODE_SLOWDOWN_EXP per animation.
	
	
		v99:
		
			- Added Sprite.Path() which returns the path a sprite is on.
			
			- Added Path.Free() which frees a path.  You must free paths like sprites before discarding the pointers to them to avoid memory leaks!
			  Freeing a path frees all sprites which are attached to it.
		
		v100:
		
			- Updated glow functonality of system to work with new DirectX7 drivers in BlitzMax.
		
		v101:
		
			- ???
		
		v102:	
		
			- Improved comments on point and vector transformation functions.
			
			- Fixed bug in TFormNormal() that would not return correct Y coordinate.
			
		v103:
		
			- Fixed bug in TFormVector() which caused it to fail under certain (most?) conditions.  This bug also caused TFormNormal() to fail.
		
		v104:
		
			- SetPath() now allows you to detach a sprite from a path while retaining the sprite's global position.

		v105:
		
			- Free() now reports the name of a sprite if you attempt to free a sprite twice.  Naming your sprites now makes debugging easier!
		
		v106:
		
			- Sprite order functions now accept floating point values.
			- You may now animate a sprite's order using Sprite.AnimateOrder()
			
		v107:
		
			- Removed Sprite.BufferImages().  Recent versions of Blitzmax no longer appear to suffer from momentary choppiness when images aren't buffered
			  to video memory before rendering.
			
		v108:
		
			- Added Animate.SetOscillations().  
			
			  This function allows you to modify MODE_SINE animations so that they repeat their motions more than once over the course of an animation.  
			
			  Ie, if you want a sprite to speed up and slow down four times as it moves across the screen, do Animate.SetOscillations(4) before you create
			  the animation which used MODE_SINE.
						
			
			- The values set with Animate.SetExponent() and Animate.SetOscillations() now reset to the defaults each time you create a new animation.
			 
			  With the exponents, this wasn't a big issue because the EXP animation modes weren't used often, but the SINE animation mode is used quite
			  a bit, and I didn't want to have to remember to reset the oscillations to 1 every time I created an animation that needed another value.
		
		v109:
		
			- Setting an animation for a sprite which has a trigger delay of 0 will now cause the sprite to take on those atrributes immediately rather
			  than at the next call to Animate.Update().  
			
			  In other words, if you add a position animation for a sprite, and that position animation is to begin immediately, then right after that 
			  function call, the sprite will be at the start position for the animation.  (Taking into account StartAge of course.)
			
			  This allows you to create an object, then set a positon animation for it, and not have to worry about other things like bullets that check
			  for collisions with it, from colliding with the invisible pre-render object at 0,0 before it can be moved by the animation system.
			
			  If this new behavior is a problem for you, you can revert to the old behavior by commenting out _Anim.Update() in Animate.Create().
			
			
			- SetOscillations() has been commented out.  Do not use it at this time as it may be removed.			
						
		v110:
		
			- Removed GLOW_SOLID constant. 
			
			- Added commands to set a fog color per sprite, set fog alpha per sprite, and animate said values.  

			  This new setup makes more sense than the GLOW_SOLID flag did, and is more flexible than setting the sprite's color.  You can still use the
			  regular x2 multiply style glow mode by setting the sprite's color over 255, but now you can apply fog on top of that if you wish as well.
				 
			  Fog is only guaranteed to work properly with sprites that use ALPHABLEND normally.  It may work with MASKBLEND sprites, but this has not
			  been tested.
			
			  Using the RELATIVE_FOG flag, you may set a sprite's fog to be affected by the parents fog settings.  Only the fog alpha will be affected in
			  this way at this time.  The fog color will always be unaffected by the parent's fog color.
						  			
		v112:
		
			- Fixed bug with Sprite.Width#() and Sprite.Height#() being returned as negative when Global was set to true, and the sprite was flipped on
			  that axis by setting the scale to be negative.
			
		v113:
		
			- Added Physics.SpriteAngle#().  This function tells you the angle of one sprite relative to another. 	
		
		v114:
		
			- Added functions for setting and getting sprite's velocity on each axis:  Vx#(), Vy#(), SetVx#(), SetVy#().
		
		v115:
		
			- Added a new STAINEDGLASS flag for sprites.  Don't use it!  It's not working as desired, and will probably be removed.
		
		v116:
		
			- The way sprites animate has now been changed.  Instead of calling Animate.UpdateAll() each frame, you must now call Sprite.Update().  
			  Also, instead of passing the frame time to the update function, you must now call Sprite.SetTimeStep() at the start of the frame.
			  
			  In addition, the physics system is now updated when you call Sprite.Update(), so you should not call Physics.UpdateAll(), and the
			  Physics.SetTimeStep() function is now defunct, as the timestep set with Sprite.SetTimeStep() is now used.   (The reason the timestep 
			  needs to be set at the start of the frame is so that the physics system has it available when you apply forces.) 
			
			  Make sure you pass the number of MILLISECONDS to the new SetTimeStep() function!  The old physics timestep function took SECONDS!
					
			  These changes are to make things simpler.  You should now be able to just apply a force to a sprite and it will move without you needing 
			  to worry about setting up the physics stuff, if you have the animation working already. 
						  
		v117:
		
			- Moved the force applying functions into the sprite type.  ApplyForce, ApplyThrust, and ApplyField are now sprite methods.  
			  
			  All you need to do to use the new methods in your old code is change this:  
				Physics.ApplyField(SpriteName, etc...) 
			  
			  To this:  
			  	SpriteName.ApplyField(etc...)
			
			- Moved some helper functions that were in the physics type into the sprite type.  SpriteDirection(), SpriteAngle#(), and SpriteDistance#() 
			  are now methods.  The same change as for the force methods will allow you to use the new setup.						
		
		v118:
		
			- Added GlobalSpace parameter to Sprite.Vx#() and Sprite.Vy#() methods.  Using this, you can determine how fast and in what direction  
			  a child sprite is moving in global space, even if it is not moving within its parent space.
			
			  Please note that at this time, velocity is completely seperate from velocity associated with animation.  If you animate a sprite moving 
			  in a sine curve on the Y axis, and give it some velocity on the X axis, the Y velocity returned will be 0.   
			
			  Animating a sprite's scale or rotation WILL affect a child's velocity, and the direction of said velcity, but scaling or rotating a 
			  parent will not ADD velocity to a child.  
			
			  Ie, a nonmoving child attached to a rotating or scaling parent will not display changes in returned velocity.  Nor will a moving child's 
			  velocity be increased or decreased by any motion of the child associated with said parent's scaling or rotation.  Scaling a parent will 
			  only increase or decrease the child's velocity by the current scale.  The rate at which the scaling is occurring will have no effect.  
			  Likewise, rotating a parent will change the direction in which the child's velocity vector points, but will not add any rotational 
			  velocity to the child.
			
	To do:

		* Viewport of sprites is not clipped by parent viewport when globalspace is true.
		* Parent viewport cannot yet be set to move with parent.

								
End Rem
																														

' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' HELPFUL TIP!
' The % sign signifies that constants are integers for SuperStrict mode.  You don't need to include it when using them!
' -----------------------------------------------------------------------------------------------------------------------------------------------------------


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' These constants are used with the Sprite.SetFlags() method.
'
' The RETAIN flags allow you to prevent a child sprite from taking on some of the properties of the parent it is rendered relative to.
'
' For example, if you want a child's position to change as the parent rotates, but you do not want the child's rotation to also change, then you just need
' to set the child to have the RETAIN_ROTATION flag, and all rotations of the parent, or the parent's parent will be ignored.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Const RETAIN_POSITION%		= 1
	Const RETAIN_ROTATION%		= 2
	Const RETAIN_SCALE%			= 4
	Const RETAIN_COLOR%			= 8		 
	Const RETAIN_ALPHA%			= 16
	Const RETAIN_ORDER%			= 32
	Const RETAIN_HIDDEN%		= 64	

	Const RELATIVE_FOG%         = 128	' Sprite's fog is relative to parent.  
										' WARNING: If parent's fog is 0, then no fog will be displayed on the child!
										
	Const RELATIVE_VIEWPORT%	= 256	' Sprite's viewport is relative to parent.  
										' WARNING: If using centerhandle images, as I reccomend you do, setting this flag wil by default cause the sprite's
										' viewport's top left corner to be at 0,0 in the parent!  If you see a half or a quarter of the sprite you expect
										' to suddenly when you enable this, you need to set the viewpoert coordinates of the top left corner to be negative!
	
	Const STAINEDGLASS%			= 512	' When this flag is enabled, a sprite will first be drawn using multiply blending (SHADEBLEND), and then again with
										' alpha blending.  This creates the effect of colored glass, where objects behind the glass are tinted the glass
										' color, and the glass itself has a certain level of transparency.   
	
	
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' These constants are used when you need to stop a certain type of animation, or determine if a certain type of animation has finished.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Const ANIM_ALL%	 	 	= 0
	Const ANIM_POSITION% 	= 1
	Const ANIM_POSITIONX% 	= 2
	Const ANIM_POSITIONY% 	= 3
	Const ANIM_ROTATION% 	= 4
	Const ANIM_SCALE%     	= 5
	Const ANIM_SCALEX%    	= 6
	Const ANIM_SCALEY%    	= 7
	Const ANIM_COLOR%     	= 8
	Const ANIM_COLORR%	 	= 9
	Const ANIM_COLORG%    	= 10
	Const ANIM_COLORB%    	= 11
	Const ANIM_ALPHA% 	 	= 12
	Const ANIM_FOG%         = 13
	Const ANIM_FOGR%        = 14
	Const ANIM_FOGG%        = 15
	Const ANIM_FOGB%        = 16
	Const ANIM_FRAME%     	= 17
	Const ANIM_ORDER%		= 18
	

' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' Mode flags:
' These flags control how the animation is played back. 
' You may combine LOOP, PINGPONG, and REVERSE as needed, and one of the following, if desired: SINE, SPEEDUP, SLOWDOWN, SPEEDUP_EXP, SLOWDOWN_EXP
'
' For example:
' MODE_LOOP|MODE_PINGPONG|MODE_SINE
'
' Important note!
' If MODE_PINGPONG is specified, then the total time it takes to complete the animation will be DOUBLE what you specify for the animation time!
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Const MODE_LOOP%      	 = 1	' Animation repeats.								(Use when you want an animation to play continuously) 	
	Const MODE_PINGPONG%  	 = 2	' Animation plays forwards then backwards.  		(Can reduce the number of animation frames you need) 
	Const MODE_REVERSE%   	 = 4	' Animation plays in reverse.  						(Can reduce the number of animation frames you need)
	
	Const MODE_SINE%      	 = 8	' Animation speeds up then slows down. 				(Make objects move in a sine wave by animating X linearly, and Y sine)
	Const MODE_SPEEDUP%   	 = 16	' Animation starts off slow and speeds up.			(Make menus accelerate as they fly off the screen)
	Const MODE_SLOWDOWN%  	 = 32	' Animation starts off fast and slows down. 		(Make menus fly onto the screen quickly then slow to a stop)
	Const MODE_SPEEDUP_EXP%  = 64	' Animation starts off slow and speeds up.  		(Sharper change than normal speedup which is done with cosine)	
	Const MODE_SLOWDOWN_EXP% = 128	' Animation starts off fast and slows down.			(Sharper change than normal speedup which is done with cosine)
			
	Const MODE_FREE% 	  	 = 256	' Sprite is freed when animation ends.  			(Useful for creating one shot sprites which you don't want to have to keep track of and save pointers to.)
	Const MODE_HIDE%	  	 = 512	' Sprite is hidden when animation ends.				(Allows you to hide a logo or menu after fading it out.  Children are hidden too.)
	Const MODE_SHOW% 		 = 1024	' Sprite is shown when animation begins.			(Allows you to show sprite after TriggerDelay elapses, or when animation starts if TriggerDelay is 0, but the latter is no different than just showing the sprite at the same time as you call the animtion command.)
	

Rem

	Some of the physics functions are designed to work on sprites which are in the same space.  Ie, those with the same parent, and on the same path.
	These functions include DoCollision(), ApplyField(), and any other function which takes two sprites as parameters.
	
	You can apply force and thrust to sprites in differnet spaces all you want, it's just when the sprites interact that interactions could get weird if
	the sprites are in different spaces.  This is especially an issue when dealing with sprites on a path colliding with sprites not on the path.
 
	Also, keep in mind that a sprite in the space of a scaled parent will move faster or slower than normal because the space it is in has been scaled.
	
End Rem


Rem
 
	The following flags may be used with the ApplyForce(), ApplyThrust(), and ApplyField() functions:


	FORCE_IMPULSE: 
	--------------
	
	An impulse in physics is a large force applied over a very short span of time.  Setting Impulse to True will apply the full force specified 
	immediately.  So, rather than a force of 10 accelerating an object with a mass of 1 at standstill to a speed of 10 over	the course of a second,
	that object will be moving at a speed of 10 immediately after you call the function, regardless of what	the time step was for the current frame.
	
	For applying gravity, you would NOT want to use FORCE_IMPULSE.


	FORCE_IGNOREMASS: 
	-----------------
	
	Allows you to apply force to a sprite in a way which treats the sprite as if it has a mass of 1.

	When would you want to ignore mass?

		* When applying gravity to an object.  Generally, you want all your objects to be accelerated at the same rate by gravity, because the mass of an
		object is miniscule compared to the mass of the earth.  You do not want a feather falling at a much more rapid rate than a lead weight because it
		has less mass for the gravity force to act upon!  (To make a feather fall slower than a lead weight, you could apply less gravity to it, or you
		could do the more correct thing and apply more air resistance to it.)

		* When you have an object that you know you want to accelerate at a speed of 10 meters per second per second, and the amount of force needed to
		get it moving at that rate is of no importance to you.
		
	When would you NOT want to ignore mass?
	
		* For most physics calculations, if you want realistic physics, you would not want to ignore mass.
		* Ie, when calculating the forces that are exchanged in a collision.
		* Or when calculating how far objects will move away from an explosion. 
		
End Rem


Const FORCE_IMPULSE%    = 1
Const FORCE_IGNOREMASS% = 2


Const SHAPE_MASK%    = 0
Const SHAPE_CIRCLE%  = 1 
Const SHAPE_RECT%    = 2 ' Not yet supported.
Const SHAPE_POLYGON% = 3 ' Not yet supported.



Type Sprite

		Global SpriteList:TList = CreateList()
		Field _Link:TLink


	' Do not access these fields.  Use the methods provided for access instead.


		Global TimeStep%
		
		Global _TFormedX#
		Global _TFormedY#
			
		
		Field _Name$

		Field _Parent:Sprite
	
		Field _Order#

		Field _Image:TImage
		Field _Frame#						
	
		Field _Blend%
	
		Field _R#, _G#, _B#
		Field _Alpha#
		
		Field _Fog#
		Field _FogR#, _FogG#, _FogB#
																																																																																																																			
		Field _X#, _Y#
		Field _Rotation#				
		Field _ScaleX#, _ScaleY#		
	
		Field _ViewportEnabled%
		Field _ViewportX#, _ViewportY#, _ViewportWidth#, _ViewportHeight#	
		Field _LocalSpaceViewport%	
			
		Field _Hidden%
		
		Field _Flags%

		Field _Path:Path
		
		Field _ShadowAlpha#
		Field _ShadowVx#
		Field _ShadowVy#
		
		
		' Physics:
		
		Field _Vx#
		Field _Vy#
		
		Field _Mass#
		Field _Elasticity#
		
		Field _AirFriction#			
		Field _GroundFriction#		
		Field _MaxSpeed#							
	
		Field _Radius#
		
		Field _CollisionID:CollisionID
		Field _OnCollision(This:Sprite, Other:Sprite)		

		Field _LastX#, _LastY#		
	
	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function creates a new sprite, and returns a pointer to it.
	'
	'	Image  : The image the sprite will use.  May be null, if, for example, you wish to simply create an invisible parent for other sprites.
	'	Order  : The order the sprite will be drawn in.  Order can be positive or negative.  Sprites with a lower order are drawn first.
	'			 If two sprites have the same order, they will be drawn in the order in which they were created.	
	'	Parent : The parent of this sprite.  A sprite does not need to have a parent, but if it does, it will be positioned relative to it.
	'
	' The sprite's blending mode, scale, color, alpha, and viewport will be set according to the current values you have set with the Max2D functions.
	' This is so that you can set the blending mode once for example, and all sprites you create from then on will use the direcred blending mode.
	'
	' Example:
	'
	' 	ThisSprite:Sprite = Sprite.Create(Image)
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Function Create:Sprite(Image:TImage=Null, Order%=0, Parent:Sprite=Null)
		End Function	


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method is called when you create a sprite via SpriteName = New Sprite.
	' It allows you to create types that extend the sprite type.  Ie: Type Fruit Extends Sprite.
	'
	' If you create a sprite using New Sprite, then you don't need to call the Create() function.  The sprite will however default to having no image, an
	' order of 0, no parent, and a radius of 0.  You will need to at least set the sprite's image after creating it if you want it to be seen.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method New()
		End Method
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method frees a sprite and its children from the list of sprites to be drawn. 
	' All animations are stopped as well, so you do not need to call Animate.Stop() before freeing a sprite.
	'
	' You MUST call this function to get a sprite to stop being drawn!
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Free()
		End Method
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method frees all the children of a sprite. 
	' It works the same as Free(), so any children of the sprite's children are also freed, and all animations on the sprites are stopped.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method FreeChildren()
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function frees all sprites with the specified name. 
	' The name is case sensitive.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Function FreeByName(Name$)
		End Function
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method allows you to set a name for a sprite.  Useful for debugging, and displaying the names of objects in your game!
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetName(NewName$)
		End Method		
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the parent for a sprite.  
	' If Parent is Null, them the sprite will detach from whichever sprite it is parented to currently.
	'
	' If StayStill is True, the sprite will not move when you change it from one parent to another.  The position it reports itself at will change instead. 
	' If StayStill is False, then the position the sprite reports itself at will not change, but its location on the screen will change.
	'
	' Here's a better explanation:
	'
	' The "position" of a sprite is relative to the sprite's parent. 
	'
	' If a sprite is positioned at 10,10, if the sprite has no parent, then the parent is really the top left corner of the screen, and the sprite will be
	' just below and to the right of that. 
	'
	' If you then change the parent, and have set StayStill to False, then the sprite will appear 10 pixels right and down from that sprite.
	'
	' If on the other hand, you set StayStill to True, the sprite will not move from the location it is at.  Instead, its internal position will change so
	' that relative to its parent, it is being rendered at the correct position.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetParent(NewParent:Sprite, StayStill%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method changes the order in which a sprite will be drawn. 
	' Sprites with a lower order are drawn first.  Order defaults to 0, and may be negative.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetOrder(NewOrder#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method changes the image the sprite is using, and resets the frame displayed to 0.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetImage(NewImage:TImage)
		End Method	
	
	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the frame of the sprite's image to be displayed.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method SetFrame(NewFrame#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the blending mode the sprite will be drawn with.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetBlend(NewBlend%)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method alters the color and brightness of the sprite.
	'
	' A sprite's color defaults to 255, 255, 255.
	' You may make the sprite 2x as bright by setting each channel to 255*2.  This is the maximum. 
	'
	' When using values over 255, the brightening effect is achieved by drawing a second copy of the sprite over the original using LIGHTBLEND.
	' This works well with SOLIDBLEND, MASKBLEND, ALPHABLEND, and LIGHTBLEND, but gives unpredictable results with SHADEBLEND.
	'
	' Unexpected and undesirable results may occur if you use values over 255 and your sprite uses alpha and has transparent or semi-transparent areas
	' which are not black.  I have not yet tested this case.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetColor(NewR#, NewG#, NewB#)
		End Method

		
		Method SetColorR(NewR#)
		End Method
			
			
		Method SetColorG(NewG#)
		End Method
		
		
		Method SetColorB(NewB#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method alters the transparency of the sprite.
	'
	' If setting the alpha of your sprites doesn't appear to work, and your sprites dissapear when you set the alpha below 0.5, then you probably forgot to
	' SetBlend(ALPHABLEND) after you set your graphics mode.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetAlpha(NewAlpha#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method alters the how much fog affects a sprite.  0 = No effect, 1 = Full effect.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetFog(NewValue#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods control the color of a sprite's fog.
	' To make a sprite flash white, set fog to 1, and set the fog color to white.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method SetFogColor(NewR#, NewG#, NewB#)
		End Method
		
		Method SetFogR(NewValue#)
		End Method

		Method SetFogG(NewValue#)
		End Method

		Method SetFogB(NewValue#)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method positions the sprite at a new location, relative to any parents it has.
	' If GlobalSpace = True, then the sprite will be positioned in screen space.
	'
	' Keep in mind that when you do this, while ScreenX# and ScreenY# will report the position you set, the sprite's X and Y position will not match, as
	' those are always relative to the sprite's parents.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetPosition(NewX#, NewY#, GlobalSpace%=False)
		End Method

	
		Method SetX(NewX#, GlobalSpace%=False)
		End Method


		Method SetY(NewY#, GlobalSpace%=False)
		End Method

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the angle at which the sprite should be drawn.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetRotation(NewRotation#)
		End Method

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method adjusts the sprite's scale.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetScale(NewScale#)
		End Method


		Method SetScale2(NewScaleX#, NewScaleY#)
		End Method


		Method SetScaleX(NewScaleX#)
		End Method


		Method SetScaleY(NewScaleY#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the viewport for the sprite. 
	' At the edge of this region, the sprite will be clipped.  Outside this region, the sprite will be invisible.  
	'
	' When a sprite is created, its viewport will be set to match the size of the current viewport.
	' This way, you can simply change the size of the viewport, and create a bunch of sprites, and change it back.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetViewport(NewX#, NewY#, NewWidth#, NewHeight#)
		End Method
	

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method allows you to set various flags for the sprite.  See constants above for usage details.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method SetFlags(NewFlags%)
		End Method	

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the path which a sprite should use.  See the path type for details on how paths work.
	' Setting Path to Null will detach the sprite from a path.
	'
	' Important notes:
	'
	' There is no way to attach a sprite to a path while retaining its global position.  This is because it is possible to have two sprites that are at the
	' same point on the screen, but at different points along the path.  
	'
	' Along the same lines, trying to get the local distance of a sprite on a path to a sprite in global space is a no-no.
	' Getting the GLOBAL distance of a sprite on a path to another sprite is fine though.
	'
	' And finally, you may detach a sprite from a path while retaining its global position by setting NewPath to Null and StayStill to True.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method SetPath(NewPath:Path, StayStill%=False)
		End Method	


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method allows you to give a sprite a shadow.
	'
	' Distance# : The distance in pixels at which the shadow should be rendered from the sprite.
	' Angle#    : Defines the direction in which the shadow is cast.  0 = right, angle increases clockwise.
	' Alpha#    : An alpha of 1 will make a dark black shadow.  An alpha of 0 will disable the shadow.
	'
	' Shadows will work with sprites set to ALPHABLEND or MASKBLEND only! 
	'
	' The sprite's alpha affects the shadow.  Fading the sprite out causes the shadow to fade out with it.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method SetShadow(Distance#, Angle#, Alpha#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' A more advanced way of setting the shadow's distance and angle using a vector. 
	' If you use SetShadowVector() instead of SetShadow() you will need to call SetShadowAlpha() to set the shadow's alpha.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method SetShadowVector(Vx#, Vy#)
		End Method

				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Adjust's the shadow's alpha.	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
						
		Method SetShadowAlpha(Alpha#)
		End Method

				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Adjust's the shadow's distance.	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method SetShadowDistance(Distance#)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Adjust's the shadow's angle.	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method SetShadowAngle(Angle#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' The following methods deal with sprite physics.  They will have no effect unless you call Physics.Update() once per frame. 
	' See the physics type below for details on how the physics system works.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This sets a sprite's radius.  A sprite's radius defaults to the smaller of one half the width or height of the sprite's image.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method SetRadius#(NewRadius#)
		End Method
																																
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This sets a sprite's mass.  A sprite's mass defaults to 1.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetMass(NewMass#)
		End Method	


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This sets a sprite's elasticity, aka its "coefficient of restitution".
	' A sprite's elasticity defaults to 1.
	'
	' An elasticity of 1 means the sprite will bounce off when it hits something.
	' An elasticity of 0 means the sprite will stick to whatever it hits.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetElasticity(NewElasticity#)
		End Method	
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Air friction increases with the square of an object's speed, and effectively sets a top speed at which an object can move.
	' If affected only by air friction an object will coast for a very long time because at slow speeds, air friction is negligible.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method SetAirFriction(NewAirFriction#)
		End Method	

																								
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Ground friction is constant, and slows an object down at a constant rate.  With ground friction alone, an object under thrust will accelerate forever.
	' However, once thrust is removed, an object experiencing ground friction will slow to a stop fairly quickly.
	'
	' Thrust must be great enough to overcome ground friction, or an object will not move at all! 
	'
	' If ground friction is set to 10, then that means that the object will decelerate at a rate of 10 pixels per second squared, and that the thrust moving
	' the object must be greater than 10 pixels per second squared to see a net increase in speed over time.
	'
	' Valid values for ground friction are 0..Infinity.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method SetGroundFriction(NewGroundFriction#)
		End Method	
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This sets a sprite's velocity. 
	' You can either pass a normal and a speed/magnitude, or leave the speed at the default of 1, and pass a vector.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetVelocity(Nx#, Ny#, Speed#=1)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods also set a sprite's velcoity, allowing you to set the sprite's velocity on each axis individually.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetVx(Vx#)
		End Method
		
		Method SetVy(Vy#)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the speed of a sprite without altering its direction. 
	' Its main purpouse is to stop a sprite from moving.
	'
	' Keep in mind that this will not stop animation.  If you're using physics to move a sprite on the Y axis via gravity, and doing an animation of the
	' sprite's X position, then the X poisition animation will continue even if you set speed to 0.
	'
	' If the current speed of the sprite is 0 then it is not moving in any direction, and setting the speed will make it move to the right at that speed.
	' This is so you can then set a new direction.  I may change this so the sprite has a speed and direction which are seperate quantities.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method SetSpeed(NewSpeed#)
		End Method

				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method changes the direction of a sprite, without altering the speed.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method SetDirection(Nx#, Ny#)
		End Method

				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method allows you to set a function which is called when one sprite collides with another. 
	'
	' You will want to become familar with it!  This function is the key to making your sprites interact with one another!
	' Only those sprites with a CollisionID set will ever call this function.  The system only checks for collisions between sprites you specify!
	' The function you specify will be called twice when a collision occurs.  Once for each sprite, with the parameters reversed.
	'
	' To use this method, make a function with any name you want like so:
	' 	Function FunctionName(This:Sprite, Other:Sprite)
	'
	' Then call this method and pass it the name of the function like so:
	' 	SpriteName.SetOnCollision(FunctionName)
	'
	'
	' Tips:
	' -----
	' Let's say you have a player sprite, and a bullet sprite. 
	'
	' When a collision occurs between them, the function is called once for each.
	'
	' The player sprite's function should check Other.CollisionID to determine what hit it. 
	' If it determines that a bullet hit it, it should decrement its own health, and maybe explode and free itself.
	'
	' The bullet sprite's function on the other hand should just play an impact explosion and free the bullet. 
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method SetCollisionFunction(FunctionPtr(This:Sprite, Other:Sprite))
		End Method

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function sets a new CollisionID for a sprite.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
						
		Method SetCollisionID(CID:CollisionID)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns the sprite's name.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Name$()
		End Method		
		
																								
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns the sprite's parent.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Parent:Sprite()
		End Method
	

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns the order the sprite will be drawn in.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
						
		Method Order#(GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns the image the sprite is using.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method Image:TImage()
		End Method
	

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns the frame of animation the sprite's image is currently set to.
	' If Clamp is set to True, then the returned frame will be clamped to the range of 0..ImageFrames-1.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method Frame#(Clamp%=False)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method gets the blending mode the sprite will be drawn with.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Blend%()
		End Method

				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' The following methods return the sprite's data in either parent space, or global (screen) space.
	' 
	' GlobalSpace = False : Method will return local state relative to the sprite's parent.  (Top-Left of screen is parent if no parent.)
	' 				True  : Method will return global state displayed on screen.
	'
	' If a sprite has no parent, then the screen's top left corner is treated as the parent, and setting GlobalSpace will effectively do nothing.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns sprite's color.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method R#(GlobalSpace%=False)
		End Method


		Method G#(GlobalSpace%=False)
		End Method


		Method B#(GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns sprite's alpha.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method Alpha#(GlobalSpace%=False)
		End Method

	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns a sprite's fog settings.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Fog#(GlobalSpace%=False)
		End Method
		
		Method FogR#(GlobalSpace%=False)
		End Method
		
		Method FogG#(GlobalSpace%=False)
		End Method
		
		Method FogB#(GlobalSpace%=False)
		End Method
			

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns sprite's position.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
						
		Method X#(GlobalSpace%=False)
		End Method
	
	
		Method Y#(GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns sprite's rotation.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Rotation#(GlobalSpace%=False)
		End Method		

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns sprite's scale.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method ScaleX#(GlobalSpace%=False)
		End Method
		
		
		Method ScaleY#(GlobalSpace%=False)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods return a sprite's velocity.
	'
	' The GlobalSpace parameter returns the sprite's velocity in global space, after its velocity has been rotated and scaled by the parent spaces.
	' A sprite could have a velocity of 0 in its own space, but a velocity of (-1,0) in global space if its parent is moving upward.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Vx#(GlobalSpace%=False)
		End Method
		
		Method Vy#(GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods return the sprite's viewport.
	' Viewports may not work on all systems, as they are hardware based in Blitzmax.
	'
	' THE FOLLOWING IS NOT YET IMPLEMENTED:
	'
	' A sprite's viewport is clipped by the viewports of its parents.  
	' Setting GlobalSpace to True here will give you whatever portion of the viewport remains after it has been clipped by all of the parent viewports.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method ViewportX#(GlobalSpace%=False)
		End Method

		Method ViewportY#(GlobalSpace%=False)
		End Method

		Method ViewportWidth#(GlobalSpace%=False)
		End Method

		Method ViewportHeight#(GlobalSpace%=False)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns the flags set for the sprite.  See constants above for usage details.
	' To check if a particular flag is set, you can test it like so:  If (SpriteName.Flags()&RETAIN_ALPHA) <> 0 Then Blah()
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Flags%()
		End Method	


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' this method returns the path a sprite is on.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Path:Path()
		End Method
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns a sprite's radius.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method Radius#(GlobalSpace%=False)
		End Method



sswift(Posted 2007) [#3]
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods tell you a sprite's width and height, in parent or global space, taking into account its current scale.
	'
	' The width and height of a sprite is the width of the sprite on it's own X axis, and the height of the sprite on it's own Y axis. 
	' Rotating the sprite therefore has no effect on these values. 
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Width#(GlobalSpace%=False)
		End Method

				
		Method Height#(GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' GetHidden returns true if the sprite is hidden.
	'
	' A sprite is hidden if it is hidden, or a parent of it is hidden.
	' A sprite will only be visible if both it, and all parents of it, are visible.
	' 
	' GlobalSpace = True  : Method returns True if the sprite or any parent of the sprite is hidden.  If it returns false, sprite is definitely visible.
	' 				False : Method returns True if the sprite is hidden.  If it returns False sprite MAY be visible.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Hidden%(GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns the speed of the current sprite, in local (parent) space.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Speed#()
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Returns the distance of OtherSprite from this sprite.
	' Distance can be either local space or global space, but if local space is used, the sprites must be in the same space!  
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method Distance#(OtherSprite:Sprite, GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method translates the sprite relative to its current location.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Translate(OffsetX#, OffsetY#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method adjusts the sprite's current angle.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Rotate(AngularOffset#)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods make the sprite visible and invisible.  Sprites default to being visible.
	'
	' If you hide a sprite, all of it's children will be hidden as well, but they will all retain their hidden state, so that when you show the parent
	' again, any of the children that were hidden when you hid the parent will remain hidden.
	'
	' This allows you to, for example, hide a menu and restore it to the state it was in when it was hidden!
	'
	' Tip:
	' If you want a hidden parent, and a visible child, then make a sprite with no image for the parent by passing Null for the image parameter.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Show()
		End Method
	

		Method Hide()
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method draws the sprite.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Draw()
		End Method
	

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns true if this sprite overlaps the specified sprite.
	' This test is pixel perfect, and takes into account rotation and scale.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Overlaps%(Other:Sprite)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method returns true if this sprite overlaps the specified region of the screen.
	' This test is pixel perfect, and takes into account rotation and scale.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method OverlapsRect%(RectX#, RectY#, RectWidth#, RectHeight#, RectRotation#=0)	
		End Method
		
		
		Method OverlapsPoint%(X#, Y#)
		End Method

																		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function draws all the sprites.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function DrawAll()		
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method is called by the SortList function when the sprites need to be updated.  You should not need to use it.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function CompareOrder%(ThisObject:Object, OtherObject:Object)
		End Function

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function transforms a point from the space of one sprite to another.
	' Specifying 0 or Null for Source or Dest specifies GLOBAL (screen) space.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function TFormPoint(X#, Y#, Source:Sprite, Dest:Sprite)
		End Function 


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function transforms a vector from the space of one sprite to another.
	' Specifying 0 or Null for Source or Dest specifies GLOBAL (screen) space.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function TFormVector(Vx#, Vy#, Source:Sprite, Dest:Sprite)
		End Function
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function transforms a normal from the space of one sprite to another.
	' Specifying 0 or Null for Source or Dest specifies GLOBAL (screen) space.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function TFormNormal(Nx#, Ny#, Source:Sprite, Dest:Sprite)
		End Function
		
								
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These functions return the last result of a TForm operation.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function TFormedX#()
		End Function
		
		
		Function TFormedY#()
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' The animation functions have the following parameters in common:
	'
	' Time        - Length of time it takes the animation to loop once, in milliseconds.
	' Flags       - See the "Mode Flags" constants section above for information on what animation mode flags are available and how to use them.
	' TiggerDelay - The time in milliseconds before the action is actually triggered.
	' StartAge    - Allows you to prematurely age the animation so that it starts at a different point than normal.  This will not affect the trigger delay!
	' -------------------------------------------------------------------------------------------------------------------------------------------------------


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These functions move a sprite from one position to another, over time.
	'
	' You may run both X and Y position animations simulataneously and with different parameters.  Keep in mind though that specifying a new PositionX() or 
	' PostionY() animation will only override the X or Y component of a previously applied Position() animation.
	'
	' You can use PositionX() and PositionY() seperately with different settings to do advanced effects like text moving in a sine wave across the screen.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method AnimatePosition(X1#, Y1#, X2#, Y2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method

		Method AnimateX(X1#, X2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method
		
		Method AnimateY(Y1#, Y2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These functions animate a sprite's scale over time.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method AnimateScale(Scale1#, Scale2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method
																				
		Method AnimateScaleX(ScaleX1#, ScaleX2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method

		Method AnimateScaleY(ScaleY1#, ScaleY2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function animates a sprite's rotation over time.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
						
		Method AnimateRotation(Rotation1#, Rotation2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function changes a sprite's color, over time.
	'
	' A sprite's default color is 255,255,255. 
	' Any value other than this will make the sprite darker or give it a color tint.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method AnimateColor(R1#, G1#, B1#, R2#, G2#, B2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function changes a sprite's alpha, over time.
	'
	' Default alpha for a sprite is 1.
	' Valid values range from 0 to 1.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method AnimateAlpha(StartAlpha#, EndAlpha#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function changes a sprite's fog, over time.
	'
	' Default fog for a sprite is 0.
	' Valid values range from 0 to 1.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method AnimateFog(StartFog#, EndFog#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function changes a sprite's fog color, over time.
	'
	' A sprite's default fog color is 255,255,255. 
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method AnimateFogColor(R1#, G1#, B1#, R2#, G2#, B2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method	
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function animates the sprite's image, over time.
	'
	' NewImage is a pointer to an image which should be applied to the sprite when the animation is triggered.
	' Set NewImage to Null to avoid changing the image.
	' Use NewImage with delayed triggers to avoid crashes caused by bad frame numbers, or use it to simply apply a new image for each animation.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method AnimateFrame(StartFrame#, EndFrame#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0, NewImage:TImage=Null)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method animates the sprite's order over time.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method AnimateOrder(StartOrder#, EndOrder#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function adjusts the the animation speed multiplier for a specific animation or all animations linked to the specified sprite.
	'
	' What this function allows you to do is for example, double or halve the speed at which all or some of the animations of the specified sprite are
	' playing back at, without losing track of the original animation speed.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetAnimationSpeed(Speed#, Transform%=ANIM_ALL)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function stops an animation that has been applied to a sprite.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method StopAnimating(Transform%=ANIM_ALL)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function tells you if a sprite is currently being animated by the system.
	'
	' You can check to see if a specific kind of transformation is complete, or check all of them at once.
	' Only transforms which have one-shot animations will ever stop animating by themselves.
	'
	' Animations on a delay but which have not yet triggered are considered active for the purposes of this function.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method Animating%(Transform%=ANIM_ALL)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function adds a force to a sprite. Force is defined in pixels per second per unit of mass. 
	'
	' Ie, discounting friction, and applied for one second, a force of 10 will accelerate a mass of 2 to a speed of 5 pixels per second.
	' Sprites default to a mass of 1, so unless you change that, forces will correspond 1:1 to speed.
	'
	' Keep in mind that if you apply a force each frame, and no friction is there to counteract it, the object will accelerate!
	'
	' Parameters:
	' -----------
	' Nx#, Ny# 	    : Normal indicating direction of force.
	' Force#   	    : The amount of force to apply.
	' Flags         : You can use flags to affect the way the force is applied to the object.
	'
	'	
	'
	' Tips:
	' -----
	' 	* If you want to specify a velocity vector rather than a speed and direction, just pass it via Nx#, Ny# and set Force# to 1.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method ApplyForce(Nx#, Ny#, Force#=1.0, Flags%=0)
		End Method
	
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Thrust is a force in sprite space, meaning it changes direction as the sprite is rotated.
	' The parameters are the same as those for ApplyForce, with (Nx#, Ny#) being in sprite space.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method ApplyThrust(Nx#, Ny#, Force#=1.0, Flags%=0)
		End Method
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function creates a force in a direction towards or away from a sprite.  Specifically, towards or away from Source. 
	' This force falls off with the square of the distance, starting at MinRadius.
	'
	' Source    : The sprite which this sprite is should move towards or away from.
	' MinRadius : Within this radius, the force will be at its maximum.  At twice this distance, the force will be halved, and so on.
	'
	' Tips:
	' 	* Use a negative force and apply it each frame to create the effect of a magnet.
	'   * Do the same, but ignore mass to create the effect of a planet with gravity.
	'   * Use a positive force with Impulse True, and apply it once to create the effect of an explosion.
	' 	* If you do not want the force to fall off with distance, use a large MinRadius.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method ApplyField(Source:Sprite, MinRadius#, Force#=1.0, Flags%=0)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function returns a normal which points from sprite A to sprite B.
	' Warning: The two sprites must be in the same space!
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
						
		Method SpriteDirection(Sprite2:Sprite, Nx# Var, Ny# Var)
		End Method
		
	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function returns the angle at which sprite2 is relative to sprite1.
	' For the angle returned, 0 = straight up, and the angle increases clockwise.
	'
	' Warning: The two sprites must be in the same space!
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method SpriteAngle#(Sprite2:Sprite) 
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function returns the distance between two sprites.
	'
	' If GlobalSpace is true, the function returns the distance between the two sprites on the screen.
	' If GlobalSpace is false, the function transforms the second sprite's position into the parent space of the first, and returns that distance.
	'
	' In other words, if sprite 1 is attached to a parent, and that parent is scaled down by 50%, then the distance calculated between the two sprites will
	' be doubled, because sprite 2's position is transformed from global space into the parent space of sprite 1, and that space is compressed 2x.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SpriteDistance#(Sprite2:Sprite, GlobalSpace%=False)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function sets the time step which the animation and physics system use. 
	' If using variable rate frame timing, then you will need to call this functions once each frame, before you apply any forces to the sprites.
	'
	' Calls to ApplyForce and ApplyThrust will use this timestep to determine the exact amount of force or thrust to apply.
	'
	' For example, let's say a frame takes 100 milliseconds to render.  First we SetTimeStep(100) at the start of our frame.  Then if we want to apply
	' gravity to a sprite, we simply go SpriteName.ApplyForce(0, 1, 9.8), and the correct amount of gravity will be added each frame!
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function SetTimeStep(NewTimeStep%)
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function updates the sprite positions via the animation system, and the physics system.  Call it once per frame before drawing the sprites,
	' and after setting the timestep.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Function Update()
		End Function
		
								
End Type



Type Animate

	Const DEFAULT_EXPONENT#     = 2.0
	Const DEFAULT_OSCILLATIONS# = 1.0

	Global List:TList = CreateList()
	
	Global Exponent#     = DEFAULT_EXPONENT#
	Global Oscillations# = DEFAULT_OSCILLATIONS#
	
	Global _LastAnimTime%
	
	Field _Link:TLink
	
	Field _Sprite:Sprite
	Field _Transform%													

	Field _StartValue#, _EndValue#							
	Field _NewImage:TImage
			
	Field _Time%												
	Field _Flags%

	Field _Age%
	Field _TriggerDelay%
	Field _StartAge%
	
	Field _Paused%
	
	Field _Speed#
	
	Field _Exponent#
	Field _Oscillations#
	
	Field _LastX#
	Field _LastY#
	

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function creates a new Animate instance.  You should not need to call it.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function Create(ThisSprite:Sprite, Transform%, StartValue#, EndValue#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0, NewImage:TImage=Null)
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method frees an animation from the list of animations to be played.  You should not call it.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Free()
		End Method

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function stops all animations that have been applied to all sprites. 
	' It also frees any sprite's which the animations were told to free upon completion.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function StopAll()
		End Function
	
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These functions pause and unpause all preexisting animations.
	' While paused, the animations will not progress or age, and the sprites attached to them will not be freed.
	'
	' New animations created after PauseAll() is called will NOT be paused.  This allows you to pause everything onscreen, then bring up a menu by creating
	' a new animation, and then resume everything once said menu is dismissed.
	'
	' Note to self:
	' I should probably change this to use a stack.  Or maybe allow one to pause all animnations of all sprites attached to a parent.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function PauseAll()
		End Function
		
		
		Function UnpauseAll()
		End Function
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' You should no longer call this function!
	'
	' This function updates all of the animated sprites. 
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Function UpdateAll()
		End Function		
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method updates an animation.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method Update()
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function tells you if any sprites with the specified name are currently being animated by the system.
	' If no name is specified, then the system checks to see if ANY sprites are being animated.
	'
	' Sprite names are case sensitive!
	'
	' You can check to see if a specific kind of transformation is complete, or check all of them at once.
	' Only transforms which have one-shot animations will ever stop animating by themselves.
	'
	' Animations on a delay but which have not yet triggered are considered active for the purposes of this function.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Function Animating%(Name$="", Transform%=ANIM_ALL)
		End Function

														
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function allows you to do a linear interpolation between two values.
	'
	' If tween is  0, then the value returned will be x1.
	' If tween is  1, then the value returned will be x1 plus 1 times the difference between x1 and x2. (Ie: x2)
	' If tween is .5, then the value returned will be x1 plus 0.5 times the difference between x1 and x2. 
	' (Ie: The value halfway between x1 and x2)
	'
	' You may also specify values for tween outside the 0..1 range.
	'
	' For example, if you specify a value of 2 for tween, then the value returned will be x1 plus 2 times the difference
	' between x1 and x2.
	'
	' It doesn't matter whether x1 or x2 is the larger number.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function TweenLinear#(X1#, X2#, Tween#)
		End Function
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function allows you to do a cosine interpolation between two values.
	' This cosine interpolation will cause the value to change slowly at first, pick up speed, and then decelerate.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function TweenCosine#(X1#, X2#, Tween#, Oscillations#)
		End Function
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function allows you to do a half cosine interpolation between two values.
	' 
	' Half = 0 : This interpolation will cause the value to change slowly at first, then pick up speed.
	' Half = 1 : This interpolation will cause the value to change quickly at first, then decelerate.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function TweenHalfCosine#(X1#, X2#, Tween#, Half%)
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function allows you to do an exponential interpolation between two values.
	' 
	' Pow# = A power of 1.0 will produce a linear tween.
	'        A power of 2.0 will cause the value to change slowly at first, then change quickly at the end.
	'		 A power of 0.5 will do the opposite, causing the value to change quickly at first then slow down.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function TweenExponential#(X1#, X2#, Tween#, Pow#=2.0)
		End Function
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function allows you to do the reverse of a linear interpolation between two values.
	'
	' Instead of specifying the tween value, you specify the value which you want the know the tween of.
	'
	' Essentially, this function will tell you where MidX# is between two other values.  If the value is between
	' the two values, then the result will be in the range of 0..1.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Function InverseTween#(X1#, X2#, MidX#)
		End Function

		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function returns true if the specified transform type is the same or a parent type of the animation's transform type.
	' For example, if transform = ANIM_POSITION, then the function will return true if AnimTF = ANIM_POSITION, ANIM_POSITIONX, or ANIM_POSITIONY
	' You should not need to use this function, it is for internal use.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
			
		Function TransformTypeMatch%(Transform%, AnimTF%)
		End Function			
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function frees all animations applied to a specific sprite and of a specific type which have already been triggered.
	' You should never need to call this function, it is used internally by the system.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function FreeTriggered(ThisSprite:Sprite, Transform%)
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function sets the exponent which will be used for the next animation created with the MODE_SPEEDUP_EXP amd MODE_SLOWDOWN_EXP flags.
	' Valid value ranges are 1.0 -> Infinity, but you will probably want to use values between 2 and 16.
	'
	' A value of 1.0 will produce a linear tween.
	' A value of 2.0 will produce a tween nearly indistinguishable from a normal cosine SPEEDUP/SLOWDOWN tween.
	' A value of 3.0 will produce a nice looking acceleration that seems snappier than the cosine tween.
	' A value of 4.0 will produce an interesting pause then a quick acceleration.
	' A value of 8.0 is good for making alpha values hang around 1.0 longer than normal before fading out.
	'
	' You can use values like 3.5 if you wish as well.  I find 3.5 looks nice for text that floats up, when combined with an alpha fade using 8.0.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Function SetExponent(NewExp#)
		End Function


End Type


Type RenderState


	Global RenderStateList:TList = CreateList()
				
	
	Field Alpha#
	Field Blend%
	Field ClsColor_R%, ClsColor_G%, ClsColor_B%
	Field Color_R%, Color_G%, Color_B%
	Field Handle_X#, Handle_Y#
	Field ImageFont:TImageFont
	Field LineWidth#
	Field MaskColor_R%, MaskColor_G%, MaskColor_B%
	Field Origin_X#, Origin_Y#
	Field Rotation#
	Field Scale_X#, Scale_Y#
	Field Viewport_X%, Viewport_Y%, Viewport_Width%, Viewport_Height%


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods allow you to save and restore the current render settings
	'
	' Each time you call the push method, the current state is placed on the stack.
	' Each time you call the pop method, the last state placed on the stack is restored and removed from the stack.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		
		Function Push()
		End Function		


		Function Pop()
		End Function


End Type


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' If a sprite is placed on a path, then moving the sprite on its X axis moves the sprite along the path, and moving it along its Y axis moves
' it perpendicular to it.
'
' Paths are relative to the space in which a sprite is.  So if a sprite is parented to another sprite, the path will be in parent space, which means you
' can scale or rotate the path, even as the child sprite is moving along it.
'
' A single path can be applied to multiple sprites.
'
' You must free a path when you are done with it by calling Path.Free()
' -----------------------------------------------------------------------------------------------------------------------------------------------------------


Type Path

	Field PointList:TList
	Field PointArray:Object[]
	Field Points%
	
	Field Length#
	
	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Create a new path and return a pointer to it.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function Create:Path()
		End Function

	
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method frees all the points in a path, and all sprites on the path.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Free()
		End Method
		
		
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Add a point to the path.
	' If AddFirst is true, the point is inserted at the start of the path, becoming the new first point in the path.
	'
	' For speed, you can set Update% to false, and only the linked list will be updated.  If you do this you MUST call UpdatePath() when you're done,
	' or sprites will continue to move along the old path instead of the new one.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method AddPoint(X#, Y#, AddFirst%=False, Update%=True)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method adjusts the position of a point.
	' It also recalculates the normals of the segments it affects, as well as the length of those segments, and of the path itself.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Method PositionPoint(Point:PathPoint, X#, Y#, Update%=True)
		End Method

				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method updates the point array so it contains the correct data for all the points in the path. 
	' You should use it when you set Update to false during calls to AddPoint or PositionPoint.  That is the only tine it is neccessary for you to do so.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method UpdatePath()
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Convert a position from path space to cartesian space.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Transform(Px#, Py#, X# Var, Y# Var)
		End Method


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' These methods take an X position along the path, and returns the normal of the segment the point lies within.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method Nx#(Px#)
		End Method
		
		
		Method Ny#(Px#)
		End Method
		
		
				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method smooths a path by setting each point to the average position of the points on either side of it.
	'
	' You will probably not need to use this function for its intended purpouse (correcting paths created from images) unless your path has thousands of
	' points in it, but you could use it to take a square path with segmented sides, and round the edges off if you were so inclined.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Smooth(Iterations%)
		End Method
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function finds the point in the PointArray which is nearest to Value# without going over.
	'
	' The function works by doing a binary search on a sorted list. 
	'
	' If you had a list of 256 points, and you stepped through them linearly, you'd have to look at, on average, 128 of them to find the one you were
	' looking for.  With a binary search, with discard half the path with each iteration.  That means that in the WORST case, in a list of 256 points, you
	' will have to examine just 8 of those points!  This is interestingly, the number of bits needed to represent 256.  Which means that you could find a
	' point in a sorted list of 65536 points by examining just 16 points!
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method FindNearestPoint:PathPoint(Value#)
		End Method
																																																																																																																																																																																																																																																																																																
End Type


Type PathPoint
	
	Field _Link:TLink
	
	Field _X#
	Field _Y#
	
	Field _SegmentLength#
	Field _SegmentDist#
	Field _SegmentNx#
	Field _SegmentNy#
		
	Method Free()
	End Method
	
End Type	



Type Physics


	Global _Vx#
	Global _Vy#
								
														
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function is now called by Animate.UpdateAll().  You should call only Animate.UpdateAll() in your main loop.
	'
	' This function moves any sprites which have had forces applied to them. 
	'
	' Before you call this function, make sure you read up on and have called SetTimeStep() at least once to inform the physics system of how much time
	' this frame took to render.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
												
		Function UpdateAll()
		End Function
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Call this function to check to see if any collisions have occured, and update the sprites that collided.
	'
	' Tip:
	' You can manually create pairs of objects to collide with the collison pair functions, and when you run this function, those pairs, in addition to
	' those defined by the collision sets, will have collisions done for them!  This is useful for special cases like colliding sprites on a path where you
	' know that a sprite at one end of a path cannot collide with any other sprites than those to either side of it.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function DoCollisions()
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function returns true if two sprites are colliding, using the specified collision shapes.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
			
		Function Colliding%(Sprite1:Sprite, Sprite2:Sprite, Shape1%, Shape2%)
		End Function		
		
				
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' Call this function when two sprites have collided, and they will bounce off one another.
	' The system will treat the sprites as colliding spheres.
	'
	' The two sprites MUST be in the same space!  
	'
	' Sprite velocities are in the space of their parents, so you cannot directly exchange the velocity for one for the velocity of another.  You could of
	' course transform the velocities into the same space before doing the collision, and then transform them back to their respective spaces, but why?
	'
	' Generally, you will want to use this function on sprites in Global space, ie, those with no parent.
	'
	' Nx#, Ny# 	: Optional collision normal.  If you want to collide sprites that behave like true rectangles, then you'll need to set this to the normal of 
	' 			  the side of the sprite that was collided with, ie, Sprite2.
	'
	' Tips:
	' If you set Sprite2 to Null, and set the collision normal to the normal of a wall, then you can collide your object with a wall of infinite mass.
	' This can be used for the borders of the screen, or any immovable obstacle in your game.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		  
		Function Collide(Sprite1:Sprite, Sprite2:Sprite, Nx#=0, Ny#=0, MoveBack%=True)
		End Function		
								

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function moves the sprites back to where they were at the start of the frame if they are overlapping.
	' It should be called after Physics.Update() (which sets _LastX# and _LastY#), and after it is determined which sprites are colliding.
	'
	' You should not call this function as you are determining which sprites are overlapping, only after all overlaps are determined! 
	' Doing otherwise will lead to unstable physics! 
	'
	' If one sprite is moving away from the other, then it is not moved back.  Only a sprite which is moving towards the other will be moved back.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function MoveBack(Sprite1:Sprite, Sprite2:Sprite)
		End Function
					
								
End Type


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This type is used to create collision ID's.  Collision ID's allow you to specify what sort of object a sprite is for the purpouses of collision.
' They're like the numbers you would enter in Blitz3D, except you don't have to worry about duplicate numbers, and this forces you into good programming
' practice by creating named variables which you then use to reference them instead of cryptic numbers.  It also allows me to optimize the search for
' sprites that need to be collided with.
'
' Example usage:
' Global CID_Bullet:CollisionID = CollisionID.Create()
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

Type CollisionID

	Field SpriteList:TList 

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function creates a new collision ID.  
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Function Create:CollisionID()
		End Function
	
End Type


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' Collisions should not be used on objects which have positional animation applied. 
' Collisions are intended for objects whose motions are controlled only via physics.
'
' Attempting to do otherwise may cause unpredictable results.  Or it might do something really cool. 
' I don't know, because I haven't tested it!  Either way, it's not supported!
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

Type CollisionSet

	'Field Enabled

	Global _List:TList = CreateList()

	Field CID1:CollisionID
	Field CID2:CollisionID
	
	Field CID1_Shape%
	Field CID2_Shape%


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function makes all sprites with a specified collision ID collide with those of the target ID.
	'
	' Along with each ID, you also specify a shape, which defines the shape of the region used to dtermine 
	'
	' Shape can be one of the following:
	'
	' 	SHAPE_MASK   : Uses sprite's mask or alpha map. (Default)
	' 	SHAPE_CIRCLE : Uses sprite's radius.
	' 	SHAPE_RECT   : Uses a rect which is the same size and rotation as the sprite.  If sprite has no image, sprite's scale is size of rect.
	'
	' You may not collide masks with circles, but other combinations are okay.
	'
	' NOTE:
	' At this time, only MASK collisions are supported.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function Create(CID1:CollisionID, CID2:CollisionID, CID1_Shape%=SHAPE_MASK, CID2_Shape%=SHAPE_MASK)
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function updates the list of objects which are colliding with one another.
	'
	' Collision Sets contain the sprites in each set, but this list contains one entry for every pair of sprites which are colliding, with no duplicates.
	' This makes it easy to loop through them all in other functions.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Function ListPairs()
		End Function

																				
End Type



Type CollisionPair

	Global _List:TList = CreateList()

	Field _Link:TLink

	Field _Sprite1:Sprite
	Field _Sprite2:Sprite

	Field _Shape1%
	Field _Shape2%


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function creates a new collision pair.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
				
		Function Create:CollisionPair(Sprite1:Sprite, Sprite2:Sprite, Shape1%, Shape2%)
		End Function


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method removes a pair from the pair list.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method Remove()
		End Method


End Type


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function returns the number of frames in an image.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Function ImageFrames%(Image:TImage)
	End Function


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function enables solid color rendering.
'
' When rendering with solid colors, the color channels of the images you blit will be overridden with the solid color specified.  The alpha channel will
' remain intact however.
'
' This allows you to render a solid color sprite, white for example, with alpha, over the original, to make it appear to glow. 
' You can vary the strength of the effect by using SetAlpha() before you blit the second pass.
'
' This function will only work properly if you have called SetColor() with the desired color beforehand.  If you change the color afterward the results will
' be unpredictable.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Function EnableSolidColor()
	End Function


' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function disables solid color rendering.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Function DisableSolidColor()
	End Function