简体   繁体   English

在游戏运行时从现有的精灵表创建精灵表?

[英]Creating a sprite sheet from existing sprite sheets while game is running?

I've been making a 2D game with XNA that will have several unique enemies. 我一直在用XNA制作2D游戏,它将有几个独特的敌人。 I have no trouble drawing separate sprites to the screen, one over the other to make no two enemies alike, but I think it might be more efficient if instead of drawing a dozen sprites per enemy, I somehow merged those sprites into one sprite sheet. 我可以毫不费力地在屏幕上绘制单独的精灵,一个又一个,不让两个敌人成为同一敌人,但是我认为,如果不是将每个精灵合成十几个精灵,而是以某种方式将这些精灵合并到一个精灵表中,那可能会更有效率。

If I have lots and lots of these enemies on the screen, will I improve performance by a worthy amount if I do merge? 如果我在屏幕上有很多这样的敌人,如果合并的话,是否可以将性能提高很多? And is there a simple way for me to create new sprite sheets in this way, or is the answer quite fiddly? 有没有一种简单的方法可以让我以这种方式创建新的Sprite工作表,或者答案很巧妙?

It can be faster to draw one sprite instead of several. 绘制一个精灵而不是多个精灵会更快。 However, I would only recommend this, if you have performance problems. 但是,如果您有性能问题,我只会建议您这样做。 Drawing sprites is quite fast with the SpriteBatch . 使用SpriteBatch快速绘制精灵。 It has the nice feature to group draw calls of the same texture, which makes it pretty fast. 它具有很好的功能,可以对相同纹理的绘图调用进行分组,因此速度非常快。 If you create a separate texture for each enemy, you can loose this feature, which could result in a performance loss. 如果为每个敌人创建一个单独的纹理,则可以放松此功能,这可能会导致性能下降。 Creating one large sprite sheet can be better, if the sheet does not get too large. 如果工作表不会变得太大,则创建一个较大的Sprite工作表可能会更好。

To create such a sheet, you have to create a texture / render target and render to it. 要创建这样的图纸,您必须创建一个纹理/渲染目标并将其渲染。 Here is how to do it with XNA. 是使用XNA的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM