Search code examples
c++cocos2d-iphonecocos2d-xparticles

Particles in cocos2d-x flicker when setPosition is changed


I'm using a particles, slightly modified CCParticleFlower with positionVar to be in form of vertical line, from top to bottom. In CCNode update I constantly change the position of the particles from left to right across the whole screen, when it reaches the right side I set x to 0 and start scrolling to the right.

The problem is when I reset the X value to 0, all particles blinks, they disappear for about one frame and appear in the next frame, it causes a nasty flickering effect.

It does not happen when I increment X values by small numbers but when the particle position is reset to its beginning position it flickers, on win32, android and ios. I’m using most recent 1.1 version (master branch)


Solution

  • I recently had something of a similar problem where the particles would jump around whenever their parent changed direction. I'm not sure if it's exactly the same problem, but here's the thread I found that helped with my problem:

    http://www.cocos2d-iphone.org/forum/topic/17167

    The relevant post:

    I just encountered the same problem and it took me a while to get to the bottom of it, >here's the low down: do not use

    [self schedule:@selector(NextFrame:)];

    Instead, use

    [self scheduleUpdate];

    and rename NextFrame: to update:

    Using a custom selector schedules your update at the very end of the CCScheduler queue, in other words, it will cause your NextFrame: method to be called AFTER the particle system's update: method, because the particle system schedules its own update method with a priority of 1. This is not good because the position of the quads for the particles are updated using the current position of the emitter, and then the emitter is moved in your NextFrame: method, which causes all the particles to be moved again because the position of the emitter is really the position of the CCNode that draws the particles. By using scheduleUpdate, you really schedule your update: method with a priority of 0, which means it will be called before the particle system's update: method and all will be well.

    So basically, add an update method to your class and call scheduleUpdate instead of manually scheduling it.