Particles not showing, bug?

Particles not showing, bug?
0.0 0



while trying to port this tutorial ( to cocos-x, I encountered a bug with particles.

I tried using cocos2D to check if it’s a bug from the example or in cocos-x and it seems it’s a cocos-x bug. The bug occurs with iOS version, and win32 as well.

By simply doing this modification to the default template, the bug occurs:

  1. Add the provided Stars1.plist file (attached) to your project
  2. Remove every childs from the default template (Hello World text, and any menu item)
  3. Add the following code in the Layer’s init method
    a) cocos2D
    CCParticleSystemQuad starsEffect = ;
    b) cocos-x
    starsEffect = CCParticleSystemQuad::particleWithFile(“Stars1.plist”);

Maybe I’m missing something, but using cocos-x there is nothing displayed on the screen, while with cocos2D you can see star particles flying from the right to the left of the screen.
I tried to debug the frame draw call, the GL seems to be called correctly but I don’t fully (yet) understand glES, so I might be missing something obious.

Anyway, if I missused the CCParticleSystemQuad class, please enlight me, otherwise maybe someone can open a bug in the tracker.

kiki (1.1 KB)


Thanks for your feedback!

I just take a test. The particle not displayed as you described.
But I think it’s because of you haven’t provided the star1.png file.

In the cocos2d-iphone, the textureImageData can be analyzed.
Maybe it’s not work well in cocos2d-x. Because cocos2d-x is only support .png and .jpg image files now(At the edge version on github it’s support .pvr images).

You can try to provide the file star1.png. If it’s still not work, please attach your image file in this topic.
Thank you once more. And hope it’s helpful!



well, looking at cocos-x source code (CCParticleSystem.cpp, starting at line 288), it looks like textureImageData is fully supported.
In fact, I traced the code into the loading function and my texture is currectly loaded from the textureImageData key from the plist file, and the CCTexture2D is correctly created with the texture data (deflated from textureImageData), and added to the texture cache. TextureID exists and is used during the rendering phase.
I just don’t understand why it’s not displayed (maybe a GL issue, caused by some uninitialized variable).

I’ll test with the Star1.png file (that I must create, since it’s embedded in the plist file), and I’ll keep you informed.


Ok, I tried with the star1.png file (generated from the textureImageData), and it’s still not showing, while if using cocos2d-iphone it is (either with the star1.png file, or directly with the data from the plist file).

Attached the image, but it won’t be of any help I think, since the image is correctly loaded from the plist file anyway.

I really think there is some unitialized variable somewhere when using the plist file.
I’ll try (in a couple hours) to create the particle directly using c++ code.


Ok, I found the bug, and it looks like it’s what I thought it was, an unintialized variable:

By simply adding this line of code just before the addChild() call, everything works properly:
starsEffect~~>setPosition );
It looks like the m_tPosition member of the CCNode is correctly set when loading the plist file, but the m_tPositionInPixels member is still at .
I took a look at cocos2d-iphone source code and I found where the error is in cocos-x:
cocos2D-iphone uses self.position = ccp; , while in cocos-x you directly set the fields of the m_tPosition bypassing the computations done by the setter function.
I suggest replacing in the CCParticleSystem.cpp file, line 202:
m_tPosition.x = atof);
m_tPosition.y = atof);
float x = atof);
float y = atof);
this~~>setPosition( ccp(x,y) );

like it is in cocos2d-iphone (tested, and it’s working)



Did you have a chance to fix this simple bug in master?


Issue #639 created. Bin will fix it ASAP. Thanks for you work, it’s not easy to find out such a fix here :slight_smile: