1

UIViewクラスに実装されているパーティクル エミッタをオーバーレイしようとしていParticleEmitterます。

を追加しようとすると、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];

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

助言がありますか?

4

1 に答える 1

1

GPUImageUIElement で CAEmitterLayer を使用する方法があるとは思いません。後者は、渡された UI 要素をラスタライズすることに依存し-renderInContext:ており、CAEmitterLayer などの一部の UI 要素は、このメソッドを介してレンダリングされません

残念ながら、この種のコンテンツを OpenGL ES に提供する別の方法はないため、CAEmitterLayer 以外の粒子効果を生成する別の方法を見つける必要があります。

于 2013-11-04T21:39:12.890 に答える