如何在Windows Mobile 7上实现SpriteSheet(Atlas)?
如何在Windows Mobile 7上实现SpriteSheet(Atlas)?
How to implement SpriteSheet (Atlas) with Windows Mobile 7?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
移动设备面临的挑战之一是如何加载许多图像并在应用程序的生命周期内仍然从移动设备获得良好的性能。
以下是有关如何在 Windows Mobile 7 中使用 Sprite Sheet 的简短说明。
什么是 Sprite Sheet 以及为什么我们需要它?
当我们创建应用程序或游戏时,通常需要呈现许多图像。
在代码中单独调用每个图像会在应用程序的生命周期内为我们带来巨大的性能开销。
对于硬件资源有限的移动设备来说,这一点非常重要
有效地使用这些精灵(图像)以获得良好的性能。
那么精灵表如何帮助我们呢?
Sprite Sheet 是包含许多小精灵(图像)的大图像文件,
因此,我们只使用一个图像文件,而不是使用许多图像!
我们的代码调用它一次,因为图像按顺序存储在该图像文件上
它还可以节省不必要的未使用空间,从而在加载时减少内存。
以下是有关如何使用 Windows Mobile 7 进行此操作的说明。
我对 Microsoft 发布的原始 KB 进行了一些修改。
A. 使管道项目可用于构建您的内容
B. 使 SpriteSheet 类可用于您的游戏
现在要实际使用我们导入的代码,我们首先将创建新的 xml 文件并将其放入内容目录中,XML 的格式应如下所示:
正如您所看到的,此 xml 包含我们将从中创建 SpriteSheet(atlas) 的图像的名称,无需需要通过 Visual Studio 将这些精灵图像添加到您的项目中,只需将图像复制到物理内容目录即可,当然这是要求您将通过 Visual Studio 将 XML 文件添加到内容文件夹项目(这不是主项目,因此请注意)
现在要实际使用 XML 文件,您需要做一些事情。
我们需要设置xml文件的属性。
内容导入器将是 XML 内容 - XNA 框架
内容处理器将是 SpriteSheetProcessor
设置属性后,我们就可以实际调用该文件了。
首先,我们将告诉我们的代码使用 SpriteSheetRuntime
因此,我们将添加
我们将声明新的 spritebatch 和 spritesheet 对象
在加载内容中,我们将执行以下操作:
在这种情况下,XML 文件将是 SpriteSheet.xml,如上面的示例。
现在我们需要通过动画显示精灵或一次显示所有精灵。
所以我们将使用下面的 spriteBatch.Draw,但在此之前我们将启动 spriteBatch
如果您查看类(SpriteBatch)您会发现很少有选项可以在屏幕上绘制,您可以选择最适合您的:
所以最终我们可以写这样的东西:
One of the challenges with mobile devices, is how to load many images and still get good performance from the mobile device during the life time of the application.
Here is a short explanation on how to use Sprite Sheet with windows mobile 7.
What is Sprite Sheet and why do we need it?
When we create application or a game usually we need to present many images.
Calling each image separately in the code create for us huge overhead performance during the life time of the application.
When it comes to mobile devices with limited hardware resources it is very important to
use these sprites(images) efficiently to get good performance.
So how the spritesheet help us?
Sprite Sheet is big image file that contain many small sprites (images),
So instead of using many many images we use only one image file only!
Our code call it once, and because the images are stored orderly on that image file
it also save unnecessary unused space resulting less memory when loading it.
Here is the explanation on how to do it with Windows Mobile 7.
I made some modification to the original KB that Microsoft published.
A. To make the pipeline project available for building your content
B. To make the SpriteSheet class available to your game
Now to actually use the Code which we imported we first will create new xml file and put in the content directory, the format of the XML should be like this:
As you can see this xml contain the names of the images that we will create SpriteSheet(atlas) from, there is NO need to add these sprites images to your project via visual studio just copy the images to the physical content directory, and of course it is require that you will add the XML file via visual studio to the Content folder Project (This is not the main project so be aware of it)
Now to actually use the XML file you need to do few things.
We need to set the property of the xml file.
Content Importer will be XML Content - XNA Framework
Content Processor will be SpriteSheetProcessor
After we set the proprty we can actually call the file.
First we will tell our code to use the SpriteSheetRuntime
So we will add
We will declare new spritebatch and spritesheet object
In the load content we will do the following:
The XML file in this case will be SpriteSheet.xml like the exaple above.
Now we need to display the sprites either by animated them or show all of them at once..
So we will use the following spriteBatch.Draw, but before that we will start the spriteBatch
if you will look at the class (SpriteBatch) you will find few options to draw on to the screen, you can choose the most suitable for you:
So eventually we can write something like that: