I am trying to create a very basic sprite image.
First off i have an existing image (Width=100px, Height=100px).
I will be looping through this image betwee
There is a lot of information about 2D-sprites in the following MSDN article: Rendering 2D sprites
Those examples are based on Microsoft's XNA, which is a platform that can be used within Visual Studio to develop games for Windows, Windows Phone and XBOX 360.
For example, to draw a sprite, you can use the following C# code (example taken from the MSDN article, XBOX 360 specific code removed):
private Texture2D SpriteTexture;
private Rectangle TitleSafe;
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
SpriteTexture = Content.Load("ship");
TitleSafe = GetTitleSafeArea(.8f);
}
protected Rectangle GetTitleSafeArea(float percent)
{
Rectangle retval = new Rectangle(
graphics.GraphicsDevice.Viewport.X,
graphics.GraphicsDevice.Viewport.Y,
graphics.GraphicsDevice.Viewport.Width,
graphics.GraphicsDevice.Viewport.Height);
return retval;
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
Vector2 pos = new Vector2(TitleSafe.Left, TitleSafe.Top);
spriteBatch.Draw(SpriteTexture, pos, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
You need to call LoadContent()
to initialize it, then you need to call GetTitleSafeArea(100)
to get the safe draw area (in this case wich 100 percent), finally you can use the Draw
method. It accepts a parameter containing an instance of the GameTime
class, which is a Snapshot of the game timing state expressed in values that can be used by variable-step (real time) or fixed-step (game time) games.
Please let me know if that helps you.