Skip to content

Commit

Permalink
Fixed v1.1 particle test where particles are added / removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Feb 6, 2012
1 parent 7538b8e commit 0ff8067
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 39 deletions.
23 changes: 0 additions & 23 deletions cocos2d/CCParticleBatchNode.m
Expand Up @@ -342,7 +342,6 @@ -(void)removeChild: (CCParticleSystem*) child cleanup:(BOOL)doCleanup
return;

NSAssert([children_ containsObject:child], @"CCParticleBatchNode doesn't contain the sprite. Can't remove it");
//<<<<<<< HEAD

[super removeChild:child cleanup:doCleanup];

Expand All @@ -355,14 +354,6 @@ -(void)removeChild: (CCParticleSystem*) child cleanup:(BOOL)doCleanup
// paticle could be reused for self rendering
[child setBatchNode:nil];

//=======
//
// // cleanup before removing, issue 1316 clean before calling super
// [self removeChildFromAtlas:child cleanup:doCleanup];
//
// [super removeChild:child cleanup:doCleanup];
//
//>>>>>>> develop
[self updateAllAtlasIndexes];
}

Expand Down Expand Up @@ -434,7 +425,6 @@ -(void) insertChild:(CCParticleSystem*) pSystem inAtlasAtIndex:(NSUInteger)index
[textureAtlas_ fillWithEmptyQuadsFromIndex:textureAtlas_.capacity - pSystem.totalParticles amount:pSystem.totalParticles];
}

//<<<<<<< HEAD
// make room for quads, not necessary for last child
if (pSystem.atlasIndex + pSystem.totalParticles != textureAtlas_.totalQuads)
[textureAtlas_ moveQuadsFromIndex:index to:index+pSystem.totalParticles];
Expand All @@ -443,19 +433,6 @@ -(void) insertChild:(CCParticleSystem*) pSystem inAtlasAtIndex:(NSUInteger)index
[textureAtlas_ increaseTotalQuadsWith:pSystem.totalParticles];

[self updateAllAtlasIndexes];
//=======
//// remove child helper
//-(void) removeChildFromAtlas:(CCParticleSystem*) pSystem cleanup:(BOOL) doCleanUp
//{
// [textureAtlas_ removeQuadsAtIndex:pSystem.atlasIndex amount:pSystem.totalParticles];
//
// //after memove of data, empty the quads at the end of array
// [textureAtlas_ fillWithEmptyQuadsFromIndex:textureAtlas_.totalQuads amount:pSystem.totalParticles];
//
// //with no cleanup the particle system could be reused for self rendering
// if (!doCleanUp) [pSystem useSelfRender];
//
//>>>>>>> develop
}

//rebuild atlas indexes
Expand Down
30 changes: 14 additions & 16 deletions tests/ParticleTest.m
Expand Up @@ -1670,7 +1670,7 @@ -(NSString *) title

-(NSString*) subtitle
{
return @"FPS should be lower than next test";
return @"v1.1 test: FPS should be lower than next test";
}

-(void) update:(ccTime) dt
Expand Down Expand Up @@ -1747,7 +1747,7 @@ -(NSString *) title

-(NSString*) subtitle
{
return @"should perform better than previous test";
return @"v1.1 test: should perform better than previous test";
}
@end

Expand All @@ -1762,14 +1762,14 @@ -(void) onEnter
background = nil;

//adds the texture inside the plist to the texture cache
batchNode_ = [CCParticleBatchNode batchNodeWithFile:@"Spiral.png" capacity:16000];
batchNode_ = [CCParticleBatchNode batchNodeWithTexture:nil capacity:16000];

[self addChild:batchNode_ z:1 tag:2];

for (int i = 0; i<6; i++) {

CCParticleSystemQuad *particleSystem = [CCParticleSystemQuad particleWithFile:@"Particles/Spiral.plist"];
[particleSystem setTexture:batchNode_.texture];
[batchNode_ setTexture:particleSystem.texture];

particleSystem.positionType = kCCPositionTypeGrouped;
particleSystem.totalParticles = 200;
Expand All @@ -1781,7 +1781,7 @@ -(void) onEnter

}

[self schedule:@selector(removeSystem) interval:5];
[self schedule:@selector(removeSystem) interval:0.5];
emitter_ = nil;

}
Expand All @@ -1791,15 +1791,11 @@ - (void) removeSystem
if ([[batchNode_ children] count] > 0)
{

/*CCARRAY_FOREACH([[batchNode_ children],aSystem)
{
CCLOG(@"pos %f %f, atlas %i",system.position.x,system.position.y,system.atlasIndex);
}*/
CCLOG(@"remove random system");
uint rand = arc4random() % ([[batchNode_ children] count] - 1);
[batchNode_ removeChild:[[batchNode_ children] objectAtIndex:rand] cleanup:YES];

CCParticleSystemQuad *particleSystem = [CCParticleSystemQuad particleWithFile:@"Particles/Spiral.plist"];
[particleSystem setTexture:batchNode_.texture withRect:CGRectMake(0.f,0.f,0.f,0.f)];
//add new

particleSystem.positionType = kCCPositionTypeGrouped;
Expand Down Expand Up @@ -1833,12 +1829,12 @@ -(void) update:(ccTime) dt

-(NSString *) title
{
return @"add and remove";
return @"Add and remove Particle System";
}

-(NSString*) subtitle
{
return @"every 2 sec 1 system disappear, 1 appears";
return @"v1.1 test: every 2 sec 1 system disappear, 1 appears";
}
@end

Expand All @@ -1859,7 +1855,7 @@ -(void) onEnter
[self addChild:batchNode_ z:1 tag:2];


for (int i = 0; i<2; i++) {
for (int i = 0; i<3; i++) {

CCParticleSystemQuad* particleSystem = [[CCParticleSystemQuad alloc] initWithTotalParticles:200];
[particleSystem setTexture:batchNode_.texture];
Expand Down Expand Up @@ -1900,16 +1896,18 @@ -(void) onEnter
particleSystem.endSpinVar = 0;

// color of particles
ccColor4F startColor = {1, i, i, 1.0f};
float color[3] = {0,0,0};
color[i] = 1;
ccColor4F startColor = {color[0], color[1], color[2], 1.0f};
particleSystem.startColor = startColor;

ccColor4F startColorVar = {0, 0, 0, 0};
particleSystem.startColorVar = startColorVar;

ccColor4F endColor = {1, i, i, 1 };
ccColor4F endColor = startColor;
particleSystem.endColor = endColor;

ccColor4F endColorVar = {0, 0, 0, 0};
ccColor4F endColorVar = startColorVar;
particleSystem.endColorVar = endColorVar;

// size, in pixels
Expand Down

0 comments on commit 0ff8067

Please sign in to comment.