How to Create a sprite Image
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<Texture2D>("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.
Let me try with some pseudocode:
Bitmap originalImage; // that is your image of 100x100 pixels
Bitmap bigImage; // this is your 3000x3000 canvas
int xPut = 0;
int yPut = 0;
int maxHeight = 0;
while (someExitCondition)
{
Bitmap imagePiece = GetImagePieceAccordingToSomeParameters(originalImage);
if (xPut + imagePiece.Width > 3000)
{
xPut = 0;
yPut += maxHeight;
maxHeight = 0;
}
DrawPieceToCanvas(bigImage, xPut, yPut, imagePiece);
xPut += imagePiece.Width;
if (imagePiece.Height > maxHeight) maxHeight = imagePiece.Height;
// iterate until done
}
declare a variable at 3000, if you put in a picture of width 250 take that away from the variable, keep doing this, this also allows you to decide if there is enough space left on that line for your next picture by seeing if the number left is larger than the width of the next picture. every time you start on a new line set the variable back to 3k and start again. solved