当调用superlayer的-renderInContext:时,CAEmitterLayer不呈现

mic*_*box 6 core-animation calayer ios caemitterlayer

我有一个绘图应用程序,我希望我的用户能够使用粒子效果作为他们的绘图的一部分.基本上,应用程序的要点是执行自定义绘图并保存到相机胶卷或通过万维网共享.

CAEmitterLayer最近对这个课程进行了修改,我认为这是一种添加粒子效果的简单而有效的方法.

我已经能够使用CAEmitterLayer实现在应用程序中在屏幕上绘制粒子.所以在屏幕上渲染效果很好.

当我使用时渲染绘图的内容

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.
Run Code Online (Sandbox Code Playgroud)

我认为发生了什么

CAEmitterLayer是在"动画"的颗粒的恒定状态.这就是为什么当我尝试渲染图层时(我还尝试渲染了layers.presentationLayerand modelLayer),动画永远不会被提交,因此屏幕外图像渲染不包含粒子.

问题是否有人渲染了CAEmitterLayer屏幕外的内容?如果是这样,你是怎么做到的?

备选问题有没有人知道任何不使用OpenGL且不是Cocos2D的粒子效果系统库?

Kur*_*vis 4

-[CALayer renderInContext:]在一些简单的情况下很有用,但在更复杂的情况下不会按预期工作。您将需要找到其他方法来进行绘图。

的文档-[CALayer renderInContext:]说:

此方法的 Mac OS X v10.5 实现不支持整个 Core Animation 合成模型。QCCompositionLayer、CAOpenGLLayer 和 QTMovieLayer 图层不会渲染。此外,不会渲染使用 3D 变换的图层,也不会渲染指定背景过滤器、过滤器、compositingFilter 或遮罩值的图层。Mac OS X 的未来版本可能会添加对渲染这些图层和属性的支持。

(这些限制也适用于 iOS。)

标题CALayer.h还说:

 * WARNING: currently this method does not implement the full
 * CoreAnimation composition model, use with caution. */
Run Code Online (Sandbox Code Playgroud)