什么时候使用CCSpriteBatchNode? [英] When to use CCSpriteBatchNode?

查看:106
本文介绍了什么时候使用CCSpriteBatchNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cocos2d我会玩一个动画。动画有大约12帧,每帧都相当大。事实上,每个框架的-hd版本是相当巨大的。

in Cocos2d I will be playing an animation. The animation has about 12 frames, and each frame is rather big. In fact, the -hd version of each frame is quite huge.

无论如何,首先,我创建它通过使用Zwoptex的所有12帧纹理。纹理大约是2048x2048。

Anyway, first, I created it by putting all 12 frames in a texture using Zwoptex. The texture is about 2048x2048.

这样我可以使用该纹理在CCSpriteBatchNode中对CCSprite进行动画处理。

This is so I can animate a CCSprite in a CCSpriteBatchNode using that texture.

但我似乎正在得到一个2级内存警告。

But I seem to be getting a level 2 memory warning.

现在我想到它,我不认为CCSpriteBatchNode应该用于一个精灵。我想这只是有用的,如果你想画大量的sprite使用相同的纹理。

Now that I think of it, I don't think CCSpriteBatchNode was supposed to be used for one sprite. I guess it was only useful if you wanted to draw lots of sprites that use the same texture.

所以我想知道:我应该框架动画子画面没有巨大的纹理)?

So I want to know: Should I animate the sprite frame by frame (no huge texture)? Or is it possible to use that huge texture but in a different way?

推荐答案

你对CCSpriteBatchNode是正确的。
CCSpriteBatchNode就像一个批处理节点:如果它包含子节点,它将在单个OpenGL调用(通常称为批量绘制)中绘制它们,如果没有CCSpriteBatchNode(在这种情况下)

You are right about CCSpriteBatchNode. CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call (often known as "batch draw"), in absence of CCSpriteBatchNode (in this case) all the "batch draw" will be called as many time as number of children (sprites).

一个CCSpriteBatchNode可以引用一个且只有一个纹理(一个图像文件,一个纹理图集),即sprite sheet由zwoptex创建。只有包含在该纹理中的CCSprites可以被添加到CCSpriteBatchNode。添加到CCSpriteBatchNode的所有CCSprites都绘制在一个OpenGL ES绘图调用中。如果CCSprites没有被添加到CCSpriteBatchNode,那么每个都需要一个OpenGL ES绘图调用,效率较低。

A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas) i.e. sprite sheet created by zwoptex. Only the CCSprites that are contained in that texture can be added to the CCSpriteBatchNode. All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call. If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient.

根据你的情况,因为在任何给定的时间只有一个纹理渲染。

According to your scenario, you don't have to use CCSpriteBatchNode since there is only one texture rendered at any given time.


所以我想知道:我应该动画sprite逐帧(没有巨大的纹理)?或者是可以使用那个巨大的纹理,但以不同的方式?

So I want to know: Should I animate the sprite frame by frame (no huge texture)? Or is it possible to use that huge texture but in a different way?

没关系。你将加载2048 x 2048纹理。要考虑的问题是为什么只有一个2048 x 2048纹理给你2级警告?你加载了多少这样的纹理。 BTW 2048 x 2048只支持上面的iPod3G / iPhone3GS(这是罚款)。

It doesn't matter. You will be loading the 2048 x 2048 texture anyways. The issue to ponder is why only one 2048 x 2048 texture is giving you a Level 2 warning? how many such textures are you loading. BTW 2048 x 2048 is only supported on iPod3G/iPhone3GS above (which is fine).

如果你加载了许多纹理(这似乎是我的真实情况)。你需要编程一些逻辑,你可以卸载纹理时,他们不是必要的。
看看下面的方法:

In case you are loading many textures (which seems true to me). You need to program some logic where you can unload the texture when they are not necessary. Do look at the following methods:

[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:fileName];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[[CCTextureCache sharedTextureCache] removeUnusedTextures];

就动画而言,你可以创建CCAnimation并使用或可以使用setDisplayFrame(CCSpriteFrame frame);

As far as animation is concerned you can create CCAnimation and use that or (depending upon your scenario) you can use setDisplayFrame(CCSpriteFrame frame);

这篇关于什么时候使用CCSpriteBatchNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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