我正在使用 cocos2d-iphone
迈出第一步。
我正在使用:
CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"textures.plist"];
使用我的 zwoptex 文件。有了这个设置,我就可以使用 frameCache
创建我的 CCSprites
,如下所示:
[CCSprite spriteWithSpriteFrameName:@"filename.png"];
到目前为止,一切都很好。现在我正在创建自己的粒子系统,我需要设置纹理。我猜测从 zwoptex 读取内容是有意义的,但我找不到方法。 我还检查了示例,它们做了类似的事情:
emitter.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.pvr"];
所以我的问题是:
- 如果我想要的不仅仅是具有不同纹理的粒子系统。我应该用它们创建一个 zwoptext 吗?如果是这样,怎么办?
- 为什么示例会执行
[[CCTextureCache sharedTextureCache] addImage: @"file"];
?是因为没有添加两次吗?
编辑: 我刚刚将其发布在 cocos2d's forum .
最佳答案
If I am going to have more than a particle system with different textures. Should I create a zwoptext with them? If so, how?
纹理表可能会提高渲染性能,因为它不会更改 OpenGL ES 状态(绑定(bind)纹理)。请查看“How to Create and Optimize Sprite Sheets in Cocos2D with Texture Packer and Pixel Formats”。我强烈建议您使用 TexturePacker创建纹理表。
Why do the examples do [[CCTextureCache sharedTextureCache] addImage: @"file"];? it's because it's not added two times?
它很容易用于加载 OpenGL 纹理。您不得使用 OpenGL ES API,例如 glTexImage2D 等。当然,CCTextureCache 始终会缓存纹理。如果指定的文件已经缓存,它会立即返回 CCTexture2D 实例。
编辑:
您可以使用 zwoptext plist 从 CCSpriteFrameCache 获取 CCTexture2D 实例。
CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"textures.plist"];
CCSpriteFrame *frameFire = [frameCache spriteFrameByName:@"particle_fire"];
CCTexture2D *texFire = frameFire.texture;
...
glBindTexture(GL_TEXTURE_2D, texFire.name);
/* You may need to use frameFire.rectInPixels and frameFire.rotated for the texture coordinates. */
...
CCSpriteFrame *frameWater = [frameCache spriteFrameByName:@"particle_water"];
CCTexture2D *texWater = frameWater.texture;
...
glBindTexture(GL_TEXTURE_2D, texWater.name);
...
关于iphone - 使用 CCTextureCache 设置粒子的纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5669850/