iphone - 使用 CCTextureCache 设置粒子的纹理

标签 iphone cocos2d-iphone particle-system zwoptex

我正在使用 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/

相关文章:

iphone - 隐藏和显示 View

iOS 纹理分配在探查器中显示内存使用量是原来的两倍

c# - 粒子统一创建星场

opengl - 现代 OpenGL 的点 Sprite 尺寸衰减

iphone - 从 iPhone 中的 UITextView 搜索文本

iphone - UIViewController 横向模式按钮不工作

c# - 在 Monotouch 中绑定(bind) extern NSString

iPhone Cocos2D - 使用特定图像启动场景

ios - Cocos2d spritesheets 和动画

opengl-es - 用于粒子系统的 GLSL PointSprite