Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>FIXED</p> <p>I was setting the number of particles to 0 as a way to pause particles animation. It works on the simulator but causes a bug on the device.</p> <p>Instead of changing the number of particles, I've created a function to change the _life and _lifeVar variables. Now it is working just fine. See the code below:</p> <p><strong>Particle System Interface</strong></p> <pre><code>@interface CCParticleMainDrill : CCParticleSystemQuad { float _saved_life, _saved_lifeVar; } // needed for BridgeSupport -(void) SetActive:(BOOL) b; -(id) init; @end </code></pre> <p><strong>Particle System Implementation</strong></p> <pre><code>@implementation CCParticleMainDrill -(id) init { return [self initWithTotalParticles:100]; } -(void) SetActive:(BOOL) b { if (b) { _life = _saved_life; _lifeVar = _saved_lifeVar; } else { _saved_life = _life; _saved_lifeVar = _lifeVar; _lifeVar = 0; _life = 0; } } -(id) initWithTotalParticles:(NSUInteger) p { if( (self=[super initWithTotalParticles:p]) ) { // _duration _duration = kCCParticleDurationInfinity; // Gravity Mode self.emitterMode = kCCParticleModeGravity; // Gravity Mode: gravity self.gravity = ccp(0,100); // Gravity Mode: speed of particles self.speed = 400; self.speedVar = 230; // Gravity Mode: radial self.radialAccel = 0; self.radialAccelVar = 0; // Gravity Mode: tagential self.tangentialAccel = 0; self.tangentialAccelVar = 0; ccBlendFunc ccbf = {GL_DST_COLOR,GL_DST_ALPHA};//{GL_SRC_ALPHA,GL_SRC_ALPHA_SATURATE}; self.blendFunc = ccbf; // _angle _angle = 90; _angleVar = 60; // emitter position //CGSize winSize = [[CCDirector sharedDirector] winSize]; self.positionType = kCCPositionTypeFree; self.position = ccp(0, 0);// ccp(winSize.width/2, winSize.height/2); self.posVar = ccp(3, 0); // _life of particles _life = 0.06; _lifeVar = 0.1; // size, in pixels _startSize = 5.0f; _startSizeVar = 1.0f; _endSize = 3.0f; _endSizeVar = 0.00f; // emits per second _emissionRate = _totalParticles/_life; // color of particles _startColor.r = 0.25f; _startColor.g = 0.14f; _startColor.b = 0.07f; _startColor.a = 1.0f; _startColorVar.r = 0.0f; _startColorVar.g = 0.0f; _startColorVar.b = 0.0f; _startColorVar.a = 0.0f; _endColor.r = 0.28f; _endColor.g = 0.19f; _endColor.b = 0.12f; _endColor.a = 0.30f; _endColorVar.r = 0.0f; _endColorVar.g = 0.0f; _endColorVar.b = 0.0f; _endColorVar.a = 0.0f; NSString *path = [[NSBundle mainBundle] pathForResource:@"particle" ofType:@"png"]; self.texture = [[CCTextureCache sharedTextureCache] addImage: path]; _saved_life = _life; _saved_lifeVar = _lifeVar; // additive self.blendAdditive = YES; } return self; } @end </code></pre> <p><strong>Adding Particle to Scene</strong></p> <pre><code>-(id) init { Armor = [CCSprite spriteWithFile:@"player.png"]; Armor.position = ccp(16, 16); [self addChild:Armor]; DrillParticles = [CCParticleMainDrill node];//[CCParticleSmoke node];// [DrillParticles setPosition:ccp(Armor.boundingBox.size.width/2, 0)]; //[DrillParticles setTotalParticles:0]; //BUGGED CODE [Armor addChild:DrillParticles z:INT_MAX]; [DrillParticles SetActive:NO]; } -(void) StopAnimation { [DrillParticles SetActive:NO]; //[DrillParticles setTotalParticles:0]; // BUGGED CODE } -(void)StartAnimation { [DrillParticles SetActive:YES]; //[DrillParticles setTotalParticles:100]; // BUGGED CODE } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload