0

我的粒子在模拟器中运行良好,但是当我使用设备(iPhone 4S - iOS 6.1)运行应用程序时,它看起来像一些奇怪的激光(见下图):

设备上的粒子: https ://dl.dropboxusercontent.com/u/58621241/IMG_2287.PNG

模拟器上的粒子: https ://dl.dropboxusercontent.com/u/58621241/Screen%20Shot%202013-06-20%20at%2018.10.15.png

这是我创建粒子系统的代码:

@implementation CCParticleMainDrill
-(id) init
{
    return [self initWithTotalParticles:100];
}

-(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;

        self.texture = [[CCTextureCache sharedTextureCache] addImage: @"particle.png"];

        // additive
        self.blendAdditive = YES;
    }

    return self;
}
@end

当我将粒子添加到场景中时,这是一个:

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];
[Armor addChild:DrillParticles z:INT_MAX];
4

1 回答 1

0

固定的

我将粒子数设置为 0 作为暂停粒子动画的一种方式。它适用于模拟器,但会导致设备上的错误。

我没有改变粒子的数量,而是创建了一个函数来改变 _life 和 _lifeVar 变量。现在它工作得很好。请看下面的代码:

粒子系统界面

@interface CCParticleMainDrill : CCParticleSystemQuad
{
    float _saved_life, _saved_lifeVar;
}
// needed for BridgeSupport
-(void) SetActive:(BOOL) b;
-(id) init;
@end

粒子系统实现

@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

将粒子添加到场景

-(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
}
于 2013-06-22T13:03:59.097 回答