Jon*_*an 3 animation image sequence sprite-sheet
我来自2D动画背景,所以当我使用动画序列时,我更喜欢使用一系列图像.对我而言,这很有意义,因为您可以轻松地从合成/编辑软件导出图像序列,并轻松定义方面.
我是游戏开发的新手,对使用精灵表感到好奇.有什么优点和缺点.文件大小是个问题吗? - 对我来说,似乎一堆小图像与一个大图像相同.此外,定义精灵的每个单独区域似乎时间繁琐.
基本上,我不明白为什么你会使用精灵表 - 请赐教.
谢谢
精灵表的性能更好,因为您将所有数据都包含在单个纹理中.假设您有1000个精灵从精灵表中播放相同的动画.绘图的过程就像是.
Set the sprite sheet texture.
Adjust UV's to show single frame of animation.
Draw sprite 0
Adjust UV's
Draw sprite 1
.
.
.
Adjust UV's
Draw sprite 998
Adjust UV's
Draw sprite 999
Run Code Online (Sandbox Code Playgroud)
使用纹理序列可能会导致以下情况的最坏情况:
Set the animation texture.
Draw sprite 0
Set the new animation texture.
Draw sprite 1
.
.
.
Set the new animation texture.
Draw sprite 998
Set the new animation texture.
Draw sprite 999
Run Code Online (Sandbox Code Playgroud)
尔加!在绘制每个精灵之前,你必须设置渲染状态以使用不同的纹理,这比调整几个UV 要慢得多.
许多(大多数?)显卡要求图像的平方尺寸。因此,例如 128x128、512x512 等。然而,许多/大多数精灵不是这样的尺寸。然后你有两个选择:
显然,第二个选择要好得多,浪费的空间更少。因此,如果您必须将多个精灵打包到一个图像中,为什么不以精灵表的形式将它们全部打包?
总而言之,加载到显卡中的图像文件必须是二次幂和平方。但是,程序可以选择将该纹理的任意矩形渲染到屏幕上;它不必是二的幂或平方。因此,将纹理与多个图像打包以最有效地利用纹理空间。