Sprites

AgateLib has a sprite class which can be used to create animated sprites. In order to use sprites, you need to add the following using directive to the top of any file you wish to use sprites:

  1. using AgateLib.Sprites;

Loading images into a sprite

Managing animations where you have several frames of animation can be tedious. Luckily, AgateLib has a fairly robust Sprite class which will do all of it for you. There are several ways to load up a sprite and add frames to it. The simplest follows:

  1. Sprite mySprite = new Sprite("sprite.png", 32, 32);
  2. Sprite mySprite = new Sprite("sprite.png", new Size(32, 32));

The above two function calls are equivalent. You specify a file, and the sprite automatically cuts out frames of the size passed (32x32 in the above example). It will automatically ignore frames which are blank.

If you have frames of animation in more than one file, you can add them after creating a sprite in this manner:

  1. mySprite.AddFrames("sprite2.png"); // loads frames from another file
  2. mySprite.AddFrames(mySurface);     // loads frames from a surface

Drawing with a sprite

Sprites have all the same drawing functions that Surfaces do. They also have a number of the same properties.

Animating sprites