How to Create a sprite Image

后端 未结 4 1559
刺人心
刺人心 2021-01-05 10:09

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

4条回答
  •  旧巷少年郎
    2021-01-05 11:04

    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
    }
    

提交回复
热议问题