Click or drag to resize

SpriteDatabase Constructor

The sprite database instantiation function. The filename can either be a file on the computer or it can be the string name of a resource (the filename without the extension. If your file is accessed by Properties.Resources.MySprites, the "filename" would be "MySprites")

Namespace:  SpriteLibrary
Assembly:  SpriteLibrary (in SpriteLibrary.dll) Version: 1.0.0.6 (1.0.0.6)
Syntax
C#
public SpriteDatabase(
	ResourceManager theResourceManager,
	string filename
)

Parameters

theResourceManager
Type: System.ResourcesResourceManager
The ResourceManager for your project. Usually Properties.Resources.ResourceManager
filename
Type: SystemString
Either a path and file (like: @"c:\users\me\Desktop\myfile.xml") or the name of a resource (like: "myfile")
Examples
This is an example of how to use a SpriteDatabase. When you begin developing your project, you want to start by creating a SpriteDatabase and pointing it to a file, and then opening up an EditorWindow.
C#
public partial class MyGameForm : Form
{
    SpriteController mySpriteController = null;
    SpriteDatabase mySpriteDatabase = null;

    public MyGameForm()
    {
        InitializeComponent();
        MainDrawingArea.BackgroundImage = Properties.Resources.Background;
        MainDrawingArea.BackgroundImageLayout = ImageLayout.Stretch;

        string Desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        string MyFile = Path.Combine(Desktop, "MySprites.xml");
        mySpriteDatabase = new SpriteDatabase(Properties.Resources.ResourceManager, MyFile);

        mySpriteController = new SpriteController(MainDrawingArea, mySpriteDatabase);

        mySpriteDatabase.OpenEditWindow();
        mySpriteDatabase.Save();
    }
}
The Editor Window will let you find the sprites that are contained in the various images you have as resources in your program, and it will save a file with those sprite templates. Any SpriteController that you have instantiated with a Sprite Database (see SpriteController(PictureBox, SpriteDatabase)) will now be able to create named sprites from the templates defined in the database. After the first use, the named sprites will be accessible from within that controller just like any other named sprites.

After you have created your SpriteDatabase file, you will want to add your file to your program resources. Then, you will change the SpriteDatabase to use the resource instead of a file. If we named the file "MySpriteDatabase.xml", and it got added to your resources with the name "MySpriteDatabase", you would pass "MySpriteDatabase" to the database instantiation.

C#
public partial class MyGameForm : Form
{
    SpriteController mySpriteController = null;
    SpriteDatabase mySpriteDatabase = null;

    public MyGameForm()
    {
        InitializeComponent();
        MainDrawingArea.BackgroundImage = Properties.Resources.Background;
        MainDrawingArea.BackgroundImageLayout = ImageLayout.Stretch;

        //string Desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        //string MyFile = Path.Combine(Desktop, "MySprites.xml");
        //mySpriteDatabase = new SpriteDatabase(Properties.Resources.ResourceManager, MyFile);
        mySpriteDatabase = new SpriteDatabase(Properties.Resources.ResourceManager, "MySprites");

        mySpriteController = new SpriteController(MainDrawingArea, mySpriteDatabase);

        //mySpriteDatabase.OpenEditWindow();
        //mySpriteDatabase.Save();
    }
}
See Also