Chad Grenier CCParticleSystemQuad position not correct
Posts 72
Added by Chad Grenier about 1 year ago

I made an effect with Particle Designer and saved it as a plist file. Loaded it into my cocos2d-x project but it does not match what I see in Particle Designer. The effect is slightly different looking, and the position of the effect does not match.

If I place the emitter at 0,0 the effect actually goes to something like -10, 10.

CCParticleSystem emitter = new CCParticleSystemQuad();
emitter->initWithFile( "fx_aura.plist" );
emitter->autorelease();
emitter->setPosition( ccp( 0.0f, 0.0f ) );
this->addChild( emitter, 1 );
Brandon Dorris RE: CCParticleSystemQuad position not correct
Posts 15
Added by Brandon Dorris 11 months ago

I'm seeing the same thing. It's generally ok with smaller textures, but larger ones seem to exacerbate the issue. I've tried moving the emitter to the right and down based on the texture size. This works for some effects and devices, but not others. I'm trying to locate the issue and will post another reply if I figure it out.

Chad, if you were able to figure out a fix for this, could you share it?

Chad Grenier RE: CCParticleSystemQuad position not correct
Posts 72
Added by Chad Grenier 11 months ago

I have not looked for a fix yet. I just stopped doing particles in my project for now and plan to revisit it later. Please do post your fix if you find one, as I'll do the same.

Brandon Dorris RE: CCParticleSystemQuad position not correct
Posts 15
Added by Brandon Dorris 11 months ago

If anyone else has any input on this, it would be appreciated. I've spent most of my day trying to figure out what's going on. Here are some things I've tried:

Moving the position of the emitter down and to the right based on the default size of the texture.
Changing the anchor point of the emitter to ccp(0.0f, 1.0f).
A combination of the two steps mentioned above.
Moving the source position to the right and down the same amount as the actual emitter position.

The part that is bugging me the most is that, depending on the device, the fixes mentioned above sometimes help and sometimes do not. An iPhone 4/4S will emit the particles from a point well beyond the texture width/height up and to the left. An iPad 2 will emit from the exact point I am trying to compensate for (it works).

Matthew Miller RE: CCParticleSystemQuad position not correct
Posts 2
Location Fairfax VA
Added by Matthew Miller 11 months ago

Remember that the iPad and iPhone have different window sizes, and particles systems, just like textures, do not scale up automatically.
If you want to place the emitter at the same location on the screen, you must calculate the position according to the window size.
Also you can set the scale of the emitter to 0.5 for the iPhone, (because iPhone screen = half iPad screen).
If you add your emitter to a CCNode, the scaling and position of that parent node will effect the emitter.
Or if you want to avoid altering your particles in code, in particle designer, you can switch between iPhone and iPad view. This should recreate your problem, and you can save two different versions of your particle system (plist) for iPhone and iPad. Then, just use the -ipad naming scheme on the plist files, it should load it automatically.

--
Matt Miller
Dingle LLC
Indie Game Developer

Brandon Dorris RE: CCParticleSystemQuad position not correct
Posts 15
Added by Brandon Dorris 11 months ago

Thanks for your input Matthew. I actually ended up making a couple test projects to figure out what was going on.

Project 1:
I added four crosshair sprites (no scaling) to a clean background and then added a particle effect at the center point of each one. I used the same coordinates I used for the sprites and added the particles to the base layer, just like the sprites. I also added a couple particle effects to the sprites themselves as children. I set the anchor point of the sprites to ccp(0.5f, 0.5f) and added the particle emitter to ccp(0.0f, 0.0f). I noticed some pretty big differences between the center of the crosshair sprites and the center of the particle effects (I used a miniature version of the crosshairs for the particle texture). It definitely wasn't consistently off on the different devices. I tried it on an iPhone 4S, iPad 2, iPad 3, iPhone 3GS, Galaxy Nexus, Galaxy SII, Nexus S, and a few other HTC and Motorola Android devices that I can't remember the name of right now.

Project 2:
Exactly the same as project 1 (character for character code-wise), but I used cocos2d-x 2.0.1. Everything lined up perfectly!

So, rather than try to figure out the problem with my project in cocos2d-1.0.1-x-0.13, I just converted my project to use 2.0.1. I am very happy with the results.


(1-5/5)