Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CAEmitterLayer not rendering when -renderInContext: of superlayer is called

I have a drawing app and I would like for my users to be able to use particle effects as part of their drawing. Basically, the point of the app is to perform custom drawing and save to Camera Roll or share over the World Wide Web.

I encounted the CAEmitterLayer class recently, which I reckon would be a simple and effective way to add particle effects.

I have been able to draw the particles onscreen in the app using the CAEmitterLayer implementation. So rendering onscreen works fine.

When I go about rendering the contents of the drawing using

CGContextRef context = UIGraphicsBeginImageContextWithSize(self.bounds.size);

// The instance drawingView has a CAEmitterLayer instance in its layer/view hierarchy
[drawingView.layer renderInContext:context];


//Note: I have also tried using the layer.presentationLayer and still nada

....
//Get the image from the current image context here for saving to Camera Roll or sharing


....the particles are never rendered in the image.

What I think is happening

The CAEmitterLayer is in a constant state of "animating" the particles. That's why when I attempt to render the layer (I have also tried render the layers.presentationLayer and modelLayer), the animations are never committed and so the off screen image render does not contain the particles.

Question Has anyone rendered the contents of a CAEmitterLayer offscreen? If so, how did you do it?

Alternate Question Does anyone know of any particle effect system libraries that don't use OpenGL and is not Cocos2D?

like image 621
micksabox Avatar asked Aug 12 '12 23:08

micksabox


People also ask

What is superlayer?

SuperLayer is building a community creating transformative web3 experiences that democratize opportunity and ownership of the internet. Why SuperLayer? Join the best community of builders in consumer crypto to develop cutting edge products and launch to market in under 6 months.

Is it possible to batch render the Master layer?

Pretty sure the master layer (where it says Scene) is NOT enabled for batch render. Kick off batch render through Maya batch render or Deadline submission, I kept getting master layer rendered.

Why does my render keep failing?

While convenient, this feature has been known to cause render problems from time to time. If your render keeps failing, you may want to try switching this option off for the time being and render with just your CPU, also known as Software Rendering. Navigate to File > Project Settings on the top menu bar.

Where is the render queue panel in after effects?

The Render Queue panel should appear at the bottom of your After Effects window. Click the blue Best Settings to open the Render Settings window where you can choose your export options such as Frame Rate and Motion Blur.


1 Answers

-[CALayer renderInContext:] is useful in a few simple cases, but will not work as expected in more complicated situations. You will need to find some other way to do your drawing.

The documentation for -[CALayer renderInContext:] says:

The Mac OS X v10.5 implementation of this method does not support the entire Core Animation composition model. QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer layers are not rendered. Additionally, layers that use 3D transforms are not rendered, nor are layers that specify backgroundFilters, filters, compositingFilter, or a mask values. Future versions of Mac OS X may add support for rendering these layers and properties.

(These limitations apply to iOS, too.)

The header CALayer.h also says:

 * WARNING: currently this method does not implement the full
 * CoreAnimation composition model, use with caution. */
like image 69
Kurt Revis Avatar answered Oct 10 '22 00:10

Kurt Revis