如何创建一个精灵图像 [英] How to Create a sprite Image

查看:73
本文介绍了如何创建一个精灵图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个非常基本的精灵图像.

I am trying to create a very basic sprite image.

首先我有一个现有的图像(宽度= 100像素,高度= 100像素).

First off i have an existing image (Width=100px, Height=100px).

我将在这张图片中循环10到100次,每次将它放在前一张旁边的精灵上.

I will be looping through this image between 10 and 100 times, each time placing it on the sprite next to the previous one.

该图片的宽度限制为3000px.

The sprite is limited to 3000px wide.

将图像彼此相邻放置是很好的,因为我可以用一种简单的方法将它们组合在一起,但是,我需要将组合图像的宽度限制为3000px,然后从新的一行开始.

Placing the images next to each other is fine, cause i can just combine them with a simple method, however, i need to limit the width of the combined images to 3000px, then start on a new line.

推荐答案

让我尝试一些伪代码:

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
}

这篇关于如何创建一个精灵图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆