2013-04-12 4 views
4

나는 CAEmitterCell을 가지고 있으며 특정 색으로 설정했습니다. 문서에 this property is animatable이 있으며, 게임 내 다른 플레이어가 여러 색상을 사용하여 애니메이트하고 싶습니다. 플레이어는 처음부터 색상을 선택합니다.CAEmitterCell Color 속성에 애니메이션 적용

여기 내가 그것을 설정할 때 내 EmitterCell입니다 :

// 
    // Emitter Cells 
    // 

    // 'New Emitter' cell configuration 
    newEmitter = [CAEmitterCell emitterCell]; 
    newEmitter.scaleSpeed = 10; 
    newEmitter.lifetime = 2.481715; 
    newEmitter.velocity = 332.3636968085106; 
    newEmitter.contents = newemitterImg; 
    newEmitter.name = @"New Emitter"; 
    newEmitter.color = [[UIColor colorWithRed:0.50 green:0.00 blue:1.00 alpha:1.00] CGColor]; 
    newEmitter.scaleRange = 4.178236607142859; 
    newEmitter.lifetimeRange = 1.6; 
    newEmitter.greenRange = -2.775558e-17; 
    newEmitter.birthRate = 40; 
    newEmitter.emissionRange = -6.283185306666667; 
    newEmitter.scale = 0; 

    // 
    // Emitter Cell Chains 
    // 
    emitter.emitterCells = [NSArray arrayWithObjects:newEmitter, nil]; 

을 그리고 여기 그냥 두 개의 서로 다른 색상을 수신 거부,이 경우 색상 변경을 테스트하고있는 곳입니다 :

-(void)changeColor { 

    if (color == 0) { 
     color = 1; 
     NSLog(@"color = 1"); 

     [UIView animateWithDuration:1.5 delay:0 options:0 animations:^{ 
      newEmitter.color = [[UIColor colorWithRed:0.50 green:0.00 blue:1.00 alpha:1.00] CGColor]; 
     } completion:^(BOOL finished) {[self performSelector:@selector(changeColor) withObject:nil afterDelay:2];}]; 
    } else { 
     color = 0; 
     NSLog(@"color = 0"); 
     [UIView animateWithDuration:1.5 delay:0 options:0 animations:^{ 
      newEmitter.color = [[UIColor colorWithRed:1.00 green:0.50 blue:0.10 alpha:1.00] CGColor]; 
     } completion:^(BOOL finished) {[self performSelector:@selector(changeColor) withObject:nil afterDelay:2];}]; 
    } 

} 

을하지만, 이걸 실행할 때 색이 변하지 않습니다. "Animatable"의 성격을 오해 했습니까? 아니면 CAEmitterCell의 경우 다르게 처리해야합니까?

답변

-1

이러한 속성을 사용하여 이미 터 색상을 애니메이션으로 만들 수 있습니다.

newEmitter.redSpeed = 1.0; 
newEmitter.greenSpeed = 1.0; 
newEmitter.blueSpeed = 1.0; 
1

CAEmitterCells는 실제로 다릅니다. 예를 들어,

1.Assign의 이름을 당신의 CAEmitterCell에 : 애니메이션이 그 작업을하려면 다음 단계를 수행해야

newEmitter.name = @"fire";

2.Access CAEmitterLayer 통해이 터의 애니메이션 속성 예 :

//Set first before doing CABasicAnimation so it sticks 
newEmitter.redSpeed = 1.0; 

//Access the property with this key path format: @"emitterCells.<name>.<property>" 
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"emitterCells.fire.redSpeed"]; 
anim.fromValue = @(0.0); 
anim.toValue = @(1.0); 
anim.duration = 1.5; 
anim.fillMode = kCAFillModeForwards; 
[emitter addAnimation:anim forKey:@"emitterAnim"]; 
+0

어떻게 Y을 색깔을 바꾸시겠습니까? 코드를 변경하면 코드가 작동하지 않는 것 같습니다. – Bobby

0

이 시도 :

[newEmitter.emitterCells[0] setColor:[[UIColor yellowColor] CGColor]];