我正在尝试让CAEmitterLayers和CAEmitterCells从它们的父进程中间的某个位置开始他们的动画。这到底有没有可能?我尝试使用beginTime和timeOffset属性,但似乎无法正常工作。
为后人添加了一些代码:(假设我希望发射器在第5秒开始)
CAEmitterLayer *emitter = [CAEmitterLayer new];
// emitter.beginTime = -5.0f; // I tried this
// emitter.timeOffset = 5.0f; // I also tried this, with beginTime = 0.0, and with beginTime = AVCoreAnimationBeginTimeAtZero
/* set some other CAEmitterLayer properties */
CAEmitterCell *cell = [CAEmitterCell new];
// cell.beginTime = -5.0f; // Then I saw that CAEmitterCell implements CAMediaTiming protocol so I tried this
// cell.timeOffset = 5.0f; // and this
/* set some other CAEmitterCell properties */
emitter.emitterCells = @[cell];
[viewLayer addSubLayer:emitter];但动画仍然从发射器生成粒子的位置开始。
再次编辑以解释我正在尝试做的事情:
假设我有一个CAEmitterLayer来模拟下雨,所以我设置了单元格来做一个从屏幕顶部开始的“下落”动画。在渲染开始的时候,我不想在“还没有下雨”的状态下开始渲染。我想从屏幕已经被雨覆盖的地方开始。
发布于 2012-08-21 11:50:27
beginTime不是相对于现在的。您需要获取相对于当前图层时间空间的当前时间,可以使用CACurrentMediaTime()函数获取。所以在你的例子中,你会这样做:
emitter.beginTime = CACurrentMediaTime() + 5.f;https://stackoverflow.com/questions/12047402
复制相似问题