我正在寻找与SpriteKit
中发射器粒子相同的效果,scale
效果可以使粒子图像根据时间变大或变小。 (例如,一个简单的红色圆圈,变大并在1秒后消失。)我找不到与scale
中相同的SpriteKit
选项。图像可以更大并保持更大,但它不会随着时间的推移而改变。
有人知道这样做的好方法吗?
由于
编辑:
这些尝试都没有奏效,你知道为什么吗?
func addParticleSceneKit(){
println("add")
var fire = SCNParticleSystem(named: "circle1.scnp", inDirectory: "art.scnassets/Particles")
fire.particleSize = 5
emitter.addParticleSystem(fire) //emitter is a SCNNode
/*
let bigger = SCNAction.runBlock { (node) -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
SCNTransaction.setAnimationDuration(1)
fire.propertyControllers = [SCNParticlePropertySize : 10.0]
})
}
emitter.runAction(bigger)
*/
//SCNTransaction.begin()
//SCNTransaction.setAnimationDuration(1)
//fire.propertyControllers = [SCNParticlePropertySize : 10.0]
//SCNTransaction.commit()
}
答案 0 :(得分:4)
SCNParticleSystem具有类似
的属性// Specifies the initial size of the particle. Animatable.
@property(nonatomic) CGFloat particleSize;
// Specifies the initial size variation of the particle. Animatable.
@property(nonatomic) CGFloat particleSizeVariation;
如果您需要更多控制,您还可以为键“SCNParticlePropertySize”提供自己的粒子属性控制器。例如,指定在粒子生命周期内如何设置动画大小。
见
// Property controllers.
// The keys for this directionary are listed in the "Particle Properties Name" section.
// The values are instances of SCNParticlePropertyController
@property(nonatomic, copy) NSDictionary *propertyControllers;
答案 1 :(得分:2)
哇。哇哇。你已经在墙上扔了很多代码只是为了看看有什么棒,但是你看过文档吗?
SCNParticlePropertyController
's initializer的方法描述包含一个代码示例,几乎完全符合您的要求 - 它可以为粒子大小设置动画效果。转载于此:
// 1. Create and configure an animation object.
let animation = CAKeyframeAnimation()
animation.values = [ 0.1, 1.0, 3.0, 0.5 ]
// 2. Create a property controller from the animation object.
let sizeController = SCNParticlePropertyController(animation: animation)
// 3. Assign the controller to a particle system, associating it with a particle property.
particleSystem.propertyControllers = [ SCNParticlePropertySize: sizeController ]
如果您只需要尺寸和尺寸而不是关键帧,则可以在步骤1中使用CABasicAnimation
。