#region File Description
//-----------------------------------------------------------------------------
// SpriteSheet.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
#if IPHONE
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
#else
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
#endif
#endregion
namespace TiledSprites
{
///
/// Stores entries for individual sprites on a single texture.
///
public class SpriteSheet
{
#region Fields
private Texture2D texture;
private Dictionary spriteDefinitions;
#endregion
#region Constructors
///
/// Create a new Sprite Sheet
///
public SpriteSheet(Texture2D sheetTexture)
{
texture = sheetTexture;
spriteDefinitions = new Dictionary();
}
#endregion
#region Methods
///
/// Add a source sprite for fast retrieval
///
public void AddSourceSprite(int key, Rectangle rect)
{
spriteDefinitions.Add(key, rect);
}
///
/// Get the source sprite texture
///
public Texture2D Texture
{
get
{
return texture;
}
}
///
/// Get the rectangle that defines the source sprite
/// on the sheet.
///
public Rectangle this[int i]
{
get
{
return spriteDefinitions[i];
}
}
///
/// A faster lookup using refs to avoid stack copies.
///
public void GetRectangle(ref int i, out Rectangle rect)
{
rect = spriteDefinitions[i];
}
#endregion
}
}