当调用superlayer的-renderInContext:时,CAEmitterLayer不呈现 [英] CAEmitterLayer not rendering when -renderInContext: of superlayer is called

查看:386
本文介绍了当调用superlayer的-renderInContext:时,CAEmitterLayer不呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我装入 CAEmitterLayer最近类,我认为这是一种简单有效的添加粒子效果的方法。

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

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

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

当我使用

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.

我认为发生了什么

CAEmitterLayer 处于动画化粒子的常量状态。这就是为什么当我尝试渲染图层时(我还尝试渲染 layers.presentationLayer 和modelLayer),动画永远不会被提交,因此屏幕外图像渲染不会包含粒子。

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.

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

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

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

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

推荐答案

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

-[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.

为文档 - [CALayer的renderInContext:] 说:


此方法的Mac OS X v10.5实现不支持
整个核心动画组合模型。
QCCompositionLayer,CAOpenGLLayer和QTMovieLayer图层不是
渲染。此外,使用3D变换的图层不是
渲染的图层,也不是指定backgroundFilters,过滤器,
compositingFilter或蒙版值的图层。未来版本的Mac OS X可能会为
添加对渲染这些图层和属性的支持。

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.

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

(These limitations apply to iOS, too.)

标题 CALayer.h 也说:

 * WARNING: currently this method does not implement the full
 * CoreAnimation composition model, use with caution. */

这篇关于当调用superlayer的-renderInContext:时,CAEmitterLayer不呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆