【问题标题】:How to make a particle image bigger with a scale effect with SceneKit?如何使用 SceneKit 使用缩放效果使粒子图像更大?
【发布时间】:2015-03-31 19:17:29
【问题描述】:

我正在寻找与SpriteKit 中发射器粒子相同的效果,scale 效果可以根据时间使粒子图像变大或变小。 (例如一个简单的红色圆圈,变大并在 1 秒后消失。)我找不到与 SpriteKit 相同的 scale 选项。图像可以更大并保持更大,但不会随着时间而改变。

有人知道这样做的好方法吗?

谢谢

编辑:

这些尝试都没有奏效,你知道为什么吗?

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()
    }

【问题讨论】:

    标签: ios scenekit particles


    【解决方案1】:

    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;
    

    【讨论】:

    • 嗨,谢谢。我尝试对其进行动画处理,并设置初始大小,但图像保持相同的初始值。我编辑了我的帖子,你能看看吗?
    【解决方案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 ]
    

    如果您只需要 from 大小和 a to 大小而不是关键帧,则可以在步骤 1 中使用 CABasicAnimation

    【讨论】:

    • 有这么令人惊讶吗? :) 喜欢哇? :) 不,我没有看propertyController类,我的错误,我直接使用了字典。感谢您的回答。
    • SCNParticleSystem.ParticleProperty.size,在 iOS 10 中,用于SCNParticlePropertySize
    猜你喜欢
    • 2019-03-29
    • 2010-12-02
    • 2021-11-18
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2021-11-18
    相关资源
    最近更新 更多