C# 推荐游戏 (XNA) 的精灵大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/726921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 22:42:54  来源:igfitidea点击:

Recommend sprite size for games (XNA)?

c#xna

提问by Khalid Abuhakmeh

What is the best size for an individual tile in a 2D sprite sheet?

2D 精灵表中单个图块的最佳尺寸是多少?

I am creating a sprite sheet and am trying to figure out what the best resolution is to use for each sprite. Is there a standard size I shouldn't go above or below?

我正在创建一个精灵表,并试图找出每个精灵使用的最佳分辨率。是否有一个标准尺寸我不应该超过或低于?

ex. 64px X 64px, 512px X 512px, etc.

前任。64 像素 X 64 像素、512 像素 X 512 像素等。

I am trying to get HD quality sprites. Think Alien Hominid, Castle Crashers, or World of Goo. Some examples would be nice too, so if you have sprite sheet example please upload them.

我正在尝试获得高清质量的精灵。想想 Alien Hominid、Castle Crashers 或 World of Goo。一些示例也很好,所以如果你有精灵表示例,请上传它们。

采纳答案by Reed Copsey

This depends on how the sprite is going to be rendered, as well as what you are going to do with them when you render them.

这取决于精灵将如何渲染,以及渲染它们时您将如何处理它们。

If you are going to avoid scaling the sprites, making them the same as their final rendered resolution as possible will help keep the quality higher. I would definitely stick to power of two texture sizes, since it does seem to help in general.

如果您打算避免缩放精灵,使它们尽可能与最终渲染的分辨率相同将有助于保持更高的质量。我肯定会坚持使用两种纹理大小的幂,因为它总体上似乎确实有帮助。

However, if you're going to be doing a lot of transformations on your sprites, particularly with rotations or scaling, you may want to go slightly larger than the resolution they will render, since the resampling may be slightly better quality. You'll want to consider how many sprites are being composited and displayed at any time, and what hardware you'll be running on (xbox, pc, both?), to determine the best options for balancing performance with texture quality.

但是,如果您要对精灵进行大量变换,尤其是旋转或缩放,您可能需要比它们渲染的分辨率稍大一些,因为重新采样的质量可能会稍好一些。您需要考虑随时合成和显示多少个精灵,以及您将在什么硬件上运行(xbox、pc,两者?),以确定平衡性能与纹理质量的最佳选项。

If you're not going too crazy with the number of sprites, though, you can probably go at a higher quality, and allow the system to downsize them as needed, and get good results.

不过,如果您对精灵的数量不至于太疯狂,您可能可以采用更高的质量,并允许系统根据需要缩小它们的大小,并获得良好的结果。

回答by Venesectrix

This may not directly answer your question, but I wanted to throw in what I've learned when using sprite sheets. Sprite sheets are great because the fewer textures that the GPU has to switch between when drawing to the screen, the better performance.

这可能不能直接回答您的问题,但我想把我在使用精灵表时学到的东西扔掉。Sprite 表很棒,因为在绘制到屏幕时 GPU 必须切换的纹理越少,性能就越好。

I would recommend that you take a look at the XNA sprite sheet example, if you haven't already. It offers a couple great benefits:

如果您还没有,我建议您查看XNA 精灵表示例。它提供了几个很大的好处:

  • It automatically packs your sprites (in different files) into one big texture. I thought keeping my artwork in separate files and having the one giant sprite sheet generated automatically would be better than keeping all my art in one file.

    For example, what if I decide I want my animations to have an extra frame in the middle? Then I have to shift around a bunch of stuff in the sprite sheet to make room for the new frame. If I'm using one file per frame, it's just a one line change to the XML file listing what goes into the sprite sheet if I want to add a new frame in the middle.

    It can be a pain to list every frame file separately, so I can see why this may not work for some people, but it was great for my project. Also, I found that the gain of being able to swap textures in and out of my sprite sheet easily was more than worth it, which will help you as you determine what size of sprites to use.

  • We ran into a problemwhen scaling sprites. I believe that link describes the issue pretty well. In any case, this sprite sheet example will automatically add a 1 pixel border (using the color of the pixel that was originally on the edge) around each sprite you add to the sprite sheet, which will protect you from seeing oddly colored borders around your sprites when scaling, because it still only draws the sprite using the original size. It just uses the extra border for interpolation instead of a nearby sprite's pixels or white space.

  • 它会自动将您的精灵(在不同文件中)打包成一个大纹理。我认为将我的作品保存在单独的文件中并自动生成一张巨大的精灵表比将我的所有作品保存在一个文件中要好。

    例如,如果我决定让我的动画在中间有一个额外的帧怎么办?然后我必须在精灵表中移动一堆东西,为新框架腾出空间。如果我每帧使用一个文件,如果我想在中间添加一个新帧,它只是对 XML 文件的一行更改,列出了进入精灵表的内容。

    单独列出每个帧文件可能会很痛苦,所以我可以理解为什么这可能对某些人不起作用,但这对我的项目非常有用。此外,我发现能够轻松地在我的精灵表中交换纹理的收益是非常值得的,这将帮助您确定要使用的精灵大小。

  • 我们在缩放精灵时遇到了问题。我相信该链接很好地描述了这个问题。在任何情况下,这个精灵表示例都会在您添加到精灵表的每个精灵周围自动添加一个 1 像素的边框(使用最初位于边缘的像素的颜色),这将防止您看到周围有奇怪颜色的边框。缩放时精灵,因为它仍然只使用原始大小绘制精灵。它只是使用额外的边框进行插值,而不是使用附近精灵的像素或空白。

Reed is correct that there really isn't any standard sprite size you should use. It depends mostly on what type of game you are doing, what type of scaling and rotating you are doing, etc. However, there are specific sizes you need to watch for when using sprite sheets. Sprite sheets are just one giant texture, but there is a limit to how big of a texture GPU's can hold in their memory. The XBOX360 supports up to 4096x4096 (I think) textures. If you're programming for Windows, then it depends on the user's graphics card. From what I've seen, it's probably best to stick with 2048x2048 on Windows, because most graphics cards can support at least that much.

Reed 是正确的,确实没有任何标准的精灵大小应该使用。这主要取决于您在做什么类型的游戏,您在做什么类型的缩放和旋转等。但是,在使用精灵表时需要注意特定的尺寸。Sprite 表只是一个巨大的纹理,但是 GPU 可以在其内存中容纳多大的纹理是有限制的。XBOX360 最多支持 4096x4096(我认为)纹理。如果您正在为 Windows 编程,那么这取决于用户的图形卡。据我所知,最好在 Windows 上坚持使用 2048x2048,因为大多数显卡至少可以支持那么多。

One last note on the sprite sheet example. I don't believe that it will watch for a maximum sprite sheet size, so if you do use it, you may want to add a couple lines to catch when the size of the generate texture is larger than you want to support.

关于精灵表示例的最后一个注释。我不相信它会监视最大精灵表大小,因此如果您确实使用它,当生成纹理的大小大于您想要支持的大小时,您可能需要添加几行来捕捉。

回答by Andrew Russell

Shawn Hargreaves recently did a series of blog posts on texture resampling and aliasing. See the top of the list of posts for Apriland the posts for May. The key word here is "Nyquist frequency" (wikipedia).

Shawn Hargreaves 最近发表了一系列关于纹理重采样和混叠的博客文章。请参阅4 月5 月帖子列表的顶部。这里的关键词是“奈奎斯特频率”(维基百科)。

In particular take a look at this post on texture aliasing. It's got nice diagrams like this:

特别是看看这篇关于纹理锯齿的帖子。它有很好的图表,如下所示:

http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/6518.image_5F00_1B896E07.png

http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/6518.image_5F00_1B896E07.png

The very, very short answer is this:

非常非常简短的答案是:

Avoid rendering more than 2x smaller than your source texture(ie: 50% of the source size or smaller). If you do need to render smaller, then use mipmaps. And if you're rotating you've got less margin for scaling downwards. Avoid scaling upwards.

避免渲染比源纹理小 2 倍以上(即:源大小的 50% 或更小)。如果确实需要渲染更小,请使用mipmaps。如果您正在旋转,则向下缩放的余地较小。避免向上缩放。

There is no advantage to using power-of-two sized textures in XNA. Just use textures at your target resolution and let XNA handle it under-the-hood.

在 XNA 中使用二次幂大小的纹理没有任何优势。只需在您的目标分辨率下使用纹理,让 XNA 在后台处理它。

As an example: If you're making a game for 1080p resolution, then scaling down to 720p is scaling down to 66.66% the size, which is perfectly acceptable.

举个例子:如果你正在制作一个 1080p 分辨率的游戏,那么缩小到 720p 就是缩小到 66.66% 的尺寸,这是完全可以接受的。