Campfire耳机:在SpriteKit中创建闪烁/可变的SKLightNode-模拟篝火照明

关于Campfire耳机的问题,在animated campfire中经常遇到, 我有一个使用 SpriteKit 中的纹理图集的动画篝火,我正在尝试模拟火会产生的可变照明。我能够通过传递随机数形式 0...1.5 来改变衰减来实现闪烁。它可以工作,但有点太疯狂了-寻找一个关于平滑它的建议,使其更加微妙和逼真-也许通过一组设定值-不确定我会怎么做?

我有一个使用 SpriteKit 中的纹理图集的动画篝火,我正在尝试模拟火会产生的可变照明。我能够通过传递随机数形式 0...1.5 来改变衰减来实现闪烁。它可以工作,但有点太疯狂了-寻找一个关于平滑它的建议,使其更加微妙和逼真-也许通过一组设定值-不确定我会怎么做?

func buildCampfire() {
        let campfireAtlas = SKTextureAtlas(named: "Campfire")
        var fireFrames: [SKTexture] = []
        
        let numImages = campfireAtlas.textureNames.count
        for i in 1...numImages {
            let fireTextureName = "campfire\(i)"
            fireFrames.append(campfireAtlas.textureNamed(fireTextureName))
        }
        animatedCampfire = fireFrames
        
        let firstFrameTexture = animatedCampfire[0]
        campfire = SKSpriteNode(texture: firstFrameTexture)
        campfire.size.height = 300
        campfire.size.width = 300
        campfire.position = CGPoint(x: 108, y: -188)
        addChild(campfire)
    }
    
    func animateCampfire() {
        campfire.run(SKAction.repeatForever(SKAction.animate(with: animatedCampfire, timePerFrame: 0.1, resize: false, restore: true)), withKey: "campfireAnimated")
    }
    
    func flickerCampfire() {
        if let campfireLight = self.childNode(withName: "//campfireLight") as? SKLightNode {
            campfireLight.falloff = CGFloat.random(in: 0..<1.5)
    
        } else {
            print("cannot find light node")
        }
    }
    
    override func update(_ currentTime: TimeInterval) {
        flickerCampfire()
    }
}

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(247)
微指数查询:在微信 /微信上关注某人的链接
上一篇
Yoyo奶茶:UnityDOTweenUI音阶 yoyo效果
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(57条)