2011-06-27 48 views

回答

0

這個怎麼樣的代碼?您需要覆蓋CCParticleSystemQuad更新:或updateQuadWithParticle:newPosition:用於指定粒子旋轉的方法。 CCParticleSystemPoint不能旋轉粒子。

@interface MyParticleSystem : CCParticleSystemQuad 
@end 

@implementation MyParticleSystem 
- (void)updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos 
{ 
    particle->rotation = ccpToAngle(particle->pos) * 180.0f/M_PI; 
    [super updateQuadWithParticle:particle newPosition:pos]; 
} 
@end 
+0

謝謝樹。我已經測試過你的代碼,但不能讓每個粒子都朝向中心。 – Huwell

0

爲了將粒子對他們的運動方向(在你的情況:向中心),你可以做到以下幾點:

  1. oldPos屬性添加到粒子tCCParticle結構中CCParticleSystem .H
  2. 初始化oldPos屬性與初始粒子的位置在initParticle:在CCParticleSystem.m
  3. 更新oldPos屬性機智h在計算新位置之前,在CCParticleSystem.m中的update:中的當前粒子位置。我在檢查粒子是否仍然存在之後立即在第512行中做這件事。
  4. 覆蓋CCParticleSystemQuad由一輝建議:

    - (void)updateQuadWithParticle:(tCCParticle *)particle 
            newPosition:(CGPoint)pos 
    { 
        CGPoint direction = ccpSub(particle->pos, particle->oldPos); 
        CGPoint n = ccpNormalize(direction); 
        CGFloat a = -CC_RADIANS_TO_DEGREES(ccpToAngle(n) - M_PI_2); 
        particle->rotation = a; 
    
        [super updateQuadWithParticle:particle newPosition:pos]; 
    }