2013-11-03 71 views
1

我想覆蓋UIViewParticleEmitter中實現的粒子發射器。uielementinput沒有顯示在gpuimage

當我嘗試添加UIView作爲uiElementInput它不顯示。相機輸入仍然有效,但不顯示粒子發射器。

更新的代碼:

//ParticleEmitter source: 

//========================================================= 
// ParticleEmitter.h 
#import <UIKit/UIKit.h> 
#import <QuartzCore/QuartzCore.h> 

@interface ParticleEmitter : UIView{ 
CAEmitterLayer *emitter; 
} 
@end 

//========================================================= 
// ParticleEmitter.m 

#import "ParticleEmitter.h" 

@implementation ParticleEmitter 

- (id)initWithFrame:(CGRect)frame 

{ 
    self = [super initWithFrame:frame]; 
if (self) { 
    // Initialization code 

    float multiplier = 0.25f; 

    CGPoint pt; 
    pt.x = (frame.origin.x+(frame.size.width/2)); 
    pt.y = (frame.origin.y+frame.size.height/2); 

    //Create the emitter layer 
    emitter = [CAEmitterLayer layer]; 
    emitter.emitterPosition = pt; 
    emitter.emitterMode = kCAEmitterLayerOutline; 
    emitter.emitterShape = kCAEmitterLayerCircle; 
    emitter.renderMode = kCAEmitterLayerAdditive; 
    emitter.emitterSize = CGSizeMake(100 * multiplier, 0); 

    //Create the emitter cell 
    CAEmitterCell* particle = [CAEmitterCell emitterCell]; 
    particle.scale=0.05; 
    particle.emissionLongitude = M_PI; 
    particle.birthRate = multiplier * 100.0; 
    particle.lifetime = multiplier*30; 
    particle.lifetimeRange = multiplier * 4.0f; 
    particle.velocity = 300; 
    particle.velocityRange = 400; 
    particle.emissionRange = 5.5; 
    particle.scaleSpeed = 0.05; // was 0.3 
    particle.alphaRange = 0.02; 
    particle.alphaSpeed = 0.5; 



    //particle.color = [[COOKBOOK_PURPLE_COLOR colorWithAlphaComponent:0.5f] CGColor]; 
    particle.contents = (__bridge id)([UIImage imageNamed:@"baloon.png"].CGImage); 
    particle.name = @"particle"; 

    emitter.emitterCells = [NSArray arrayWithObject:particle]; 
    [self.layer addSublayer:emitter]; 


    [CATransaction begin]; 
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 
    // emitter.emitterPosition = pt; 
    [CATransaction commit]; 



     } 


return self; 

}

// =========================== ==============================

//我如何使用GPUimage的粒子發射器:

  newfilter = [[GPUImageSepiaFilter alloc] init]; 

     blendFilter = nil; 


     blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; 
     blendFilter.mix = 1.0; 


     CGRect pviewFrame = CGRectMake(0, 0, 640, 480); 
     UIView *pView = [[ParticleEmitter alloc] initWithFrame:pviewFrame]; 


     uiElementInput = [[GPUImageUIElement alloc] initWithView:pView]; 


     [newfilter addTarget:blendFilter]; 
     [uiElementInput addTarget:blendFilter]; 



     __unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput; 

     [newfilter setFrameProcessingCompletionBlock:^(GPUImageOutput *newfilter, CMTime frameTime){ 
      pView.alpha = 0.9; 
       [weakUIElementInput update]; 
     }]; 


     [newfilter addTarget:filterView]; 
     [videoCamera addTarget:newfilter]; 

// ==== ================================================== ===從FilterShowcase //例的代碼與文字的工作原理:

 newfilter = [[GPUImageSepiaFilter alloc] init]; 

     blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; 
     blendFilter.mix = 1.0; 

     NSDate *startTime = [NSDate date]; 

     UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 640.0f, 480.0f)]; 
     timeLabel.font = [UIFont systemFontOfSize:17.0f]; 
     timeLabel.text = @"Time: 0.0 s"; 
     timeLabel.textAlignment = UITextAlignmentCenter; 
     timeLabel.backgroundColor = [UIColor clearColor]; 
     timeLabel.textColor = [UIColor whiteColor]; 

     uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel]; 

     [newfilter addTarget:blendFilter]; 
     [uiElementInput addTarget:blendFilter]; 


     __unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput; 

     [newfilter setFrameProcessingCompletionBlock:^(GPUImageOutput * newfilter, CMTime frameTime){ 
      timeLabel.text = [NSString stringWithFormat:@"Time: %f s", -[startTime timeIntervalSinceNow]]; 
      [weakUIElementInput update]; 
     }]; 

     [newfilter addTarget:filterView]; 

     [blendFilter addTarget:filterView]; 

     [videoCamera addTarget:newfilter]; 

// ========================== ===============================

有什麼建議嗎?

回答

1

我不認爲有一種方法可以使用帶有GPUImageUIElement的CAEmitterLayer。後者取決於-renderInContext:來柵格化您傳遞給它的UI元素,以及一些UI元素,如CAEmitterLayer will not be rendered via this method

不幸的是,沒有其他方法可以將這種內容提供給OpenGL ES,因此您需要找到另一種生成粒子效果的方法,而不是CAEmitterLayer。