Overview
 Top Next

The Sprite library allows you to easily manage animated moving sprites.
This library is based on Andy Beaulieo's Asprite.Net which is an open source project.
The code was heavily modified and improved by Andrew Graham.
You can use this library in commercial projects.
It can be used on both the desktop and the device.

The sprites engine advances in discrete steps.
In each step (tick) sprites move to their next position, sprites are animated and collisions are checked.
Usually a timer will be used to create these ticks.

There are two objects types in this library.
The first type is GameWindow. The GameWindow is the surface that holds, manages and displays the active and inactive sprites.
It should be added to a form using GameWindow.New1.
The second type is Sprite which represents a single sprite.
Sprites could be animated by loading an image that includes the frames sequence.

See the Sprites example for a complete demonstration.
Most code snippets in this manual are based on that example.

Version 1.3 of this library adds some new Sprite methods - LoadBitmap, LoadFile and LoadFrames, New4 and some additional Sprite properties - Data, DataArray, DestinationX, DestinationY, HasDestination, FrameBitmaps, FrameCount, FrameForward, ID, IsAnimated, IsCollider, IsContained and IsVisible. GameWindow aquires some new methods - EraseSprite(index), GetSpriteID(id), SpriteOnScreen(index), SpriteOnScreenID(ID), SpriteReplace(sprite, index), a new property - CheckSpriteCollisions and a new event CollisionDestination.

GameWindow is now AutoScale aware in that its size will scale properly. All other library operations are carried out at native display resolution.

The default settings for new properties are all compatible with existing code, however version 1.3 of this library introduces some changes in behaviour over earlier versions that might affect existing code. The changes were necessary to provide a consistent model of how Sprites are moved and drawn. The changes are as follows.

a) The GameWindow now draws itself properly as a Windows Control should, that is in response to Paint events. Previously it didn't and this could cause flashing of the GameWindow and even its' non-appearance under certain conditions.

b) When a collision event occurs the Sprite X and Y positions now correspond to those displayed in the game window. Previously the X and Y positions were one tick ahead of the displayed position because the library drew then moved and then checked for collisions. Now the library moves then draws then checks for collisions so giving consistency between Sprite properties and the game window. Any code that compensated for this may need changing. Note because of this sequence of operations a Sprite added with a velocity will first be drawn after it's first move with that velocity.

c) Sprite.IntersectsPoint fixes a bug that gave illogical intersection results and didn't permit single pixel Sprites so it may now produce different results to previously.

d) CollisionMouse events now occur in the reverse order to what they did previously to conform to the order that you might expect. Sprites added later than earlier Sprites are drawn on top of the earlier ones and their CollisionMouse events occur first.

e) Sprite to Sprite collisions now only cause a single Collision event whereas previously the event occurred twice, once for each Sprite. This improvement increases performance by halving the time taken in the Tick method for processing Sprite collisions and simplifies the code in situations where the result of two Sprites colliding is only wanted to be invoked once.