我有一个绘图应用程序,我希望我的用户能够使用粒子效果作为他们绘图的一部分。基本上,该应用程序的要点是执行自定义绘制和保存到Camera Roll或通过万维网共享。
我最近统计了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.我认为正在发生的事情
CAEmitterLayer处于为粒子设置动画的恒定状态。这就是为什么当我尝试渲染层时(我也尝试过渲染layers.presentationLayer和modelLayer),动画永远不会被提交,因此离屏图像渲染不包含粒子。
问:有人在屏幕外呈现过CAEmitterLayer的内容吗?如果是这样,你是怎么做到的?
另一个问题:有没有人知道任何不使用OpenGL也不是Cocos2D的粒子效果系统库?
发布于 2012-08-13 07:53:00
-[CALayer renderInContext:]在一些简单的情况下很有用,但在更复杂的情况下不会像预期的那样工作。你需要找到一些其他的方法来做你的画。
The documentation for -[CALayer renderInContext:]说:
此方法的Mac v10.5实现不支持整个核心动画合成模型。不会渲染QCCompositionLayer、CAOpenGLLayer和QTMovieLayer层。此外,不会渲染使用3D变换的图层,也不会渲染指定backgroundFilters、滤镜、compositingFilter或遮罩值的图层。Mac OS X的未来版本可能会添加对渲染这些层和属性的支持。
(这些限制也适用于iOS。)
头CALayer.h还说:
* WARNING: currently this method does not implement the full
* CoreAnimation composition model, use with caution. */发布于 2016-08-11 03:08:03
我能够让我的CAEmitterLayer在其当前动画状态下正确地呈现为图像
Swift
func drawViewHierarchyInRect(_ rect: CGRect,
afterScreenUpdates afterUpdates: Bool) -> Bool
Objective-C
- (BOOL)drawViewHierarchyInRect:(CGRect)rect
afterScreenUpdates:(BOOL)afterUpdates在当前上下文中
UIGraphicsBeginImageContextWithOptions(size, false, 0)并将afterScreenUpdates设置为true|YES
祝你好运:D
https://stackoverflow.com/questions/11926690
复制相似问题