1

my game use several particle systems. every time i use the first particle system, stars.plist for example, the next particle to be displayed will use the texture of stars.plist. (so if next particle is rain, then will be a rain of stars :( I use [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile: @""], like:

CCParticleSystem* rain = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"rain.plist"];
[self addChild:rain z:-1];

and before initializing the rain, i have a call to preload the particle simply using:

[ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"rain.plist"];

then if my next particle to play is meteor.plist, the texture used is still the rain.plist's texture.

i use the same way to display meteor:

    NSString* fn = [NSString stringWithFormat:@"meteor%i.plist", random];
    CCParticleSystem* meteor = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:fn];

I've tried CCParticleQuad and CCParticlePoint, in both 3gs and iPhone 4 and simulator, but still the same problem.

OMGPOP
  • 1,995
  • 8
  • 52
  • 95
  • How do you provide the texture? Is it encoded in the `.plist` file or is it a separate file? I've had similar problems with textures that are embedded in the plist before, that's why I'm asking. – bummzack Feb 02 '12 at 09:51
  • so then you changed to separated files and it worked? – OMGPOP Feb 02 '12 at 09:55

1 Answers1

3

If the texture data is embedded within the .plist file, cocos2d will extract that data and store it as a texture internally. The texture is stored with the texture filename as key, so if you have two particle-systems that use the same texture-filename internally, then the texture that was loaded first will be applied for all subsequent uses of the same texture filename!

An easy way to check this is looking at your .plist file and search the textureFileName key. This key should be different for each texture. Since the image-data is embedded in your .plist file, you can change this value to anything you want.. eg. starparticle.png for your stars, rainparticle.png for the rain, etc. Just use something unique for every unique texture.

If that fails, you could still apply the texture manually, by loading it from a file like this:

[rain setTexture: [[CCTextureCache sharedTextureCache] addImage:"particleTexture.png"]];
bummzack
  • 5,805
  • 1
  • 26
  • 45
  • 1
    some of my particle use (null).tiff as textureFileName. what should i do? – OMGPOP Feb 02 '12 at 10:42
  • @Let'sSpotIt just edit the file and give each texture an unique filename... as I wrote in my answer. Eg. `rainparticle.png` for the rain particle system and `starparticle.png` in the star particle system etc... – bummzack Feb 02 '12 at 10:48
  • i changed it anyway, and it worked. i wonder why particle designer set the texture to have the same name. – OMGPOP Feb 02 '12 at 10:59