3

で最初の一歩を踏み出していcocos2d-iphoneます。

私は使っている:

CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"textures.plist"];

私のzwoptexファイルを使用します。そのセットを使用して、次のようにCCSprites使用して作成しています。frameCache

[CCSprite spriteWithSpriteFrameName:@"filename.png"];

ここまでは順調ですね。現在、独自のパーティクル システムを作成しており、テクスチャを設定する必要があります。zwoptex から読み取るのは理にかなっていると思いますが、それを行う方法が見つかりませんでした。例も確認しましたが、次のようなことを行います。

emitter.texture = [[CCTextureCache sharedTextureCache] addImage: @"fire.pvr"];

だから私の質問は:

  • テクスチャが異なる複数のパーティクル システムを使用する場合。それらを使用して zwoptext を作成する必要がありますか? もしそうなら、どのように?
  • 例がなぜそうするのです[[CCTextureCache sharedTextureCache] addImage: @"file"];か?2回追加されていないからですか?

編集: cocos2d のフォーラムにこれを投稿しました。

4

1 に答える 1

6

If I am going to have more than a particle system with different textures. Should I create a zwoptext with them? If so, how?

A texture sheet might improve the performance for rendering, because it would not change OpenGL ES state (binding textures). Please take a look at "How to Create and Optimize Sprite Sheets in Cocos2D with Texture Packer and Pixel Formats". I strongly recommend you to use TexturePacker to create texture sheets.

Why do the examples do [[CCTextureCache sharedTextureCache] addImage: @"file"];? it's because it's not added two times?

It is easy to use for loading OpenGL texture. You must not use OpenGL ES API such as glTexImage2D or so forth. Also, of course, CCTextureCache always caches textures. It returns immediately CCTexture2D instance if the specified file is already cached.

EDIT:

You can get CCTexture2D instance from CCSpriteFrameCache with zwoptext plist.

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);
...
于 2011-04-14T21:54:00.893 に答える