Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将AvSpeechSynthesis与我的场景中的另一个动画同步_Ios_Swift - Fatal编程技术网

Ios 将AvSpeechSynthesis与我的场景中的另一个动画同步

Ios 将AvSpeechSynthesis与我的场景中的另一个动画同步,ios,swift,Ios,Swift,我希望同步场景中多个动作的完成(例如语音、视频和动画),并在一组中的多个动作完成后触发另一个动作。下面这个简单的例子在演讲和行动完成后打印出一些东西 import SpriteKit import PlaygroundSupport import AVFoundation let start = CGPoint(x: 100, y: 50) let end = CGPoint(x: 200, y: 50) let radius: CGFloat

我希望同步场景中多个动作的完成(例如语音、视频和动画),并在一组中的多个动作完成后触发另一个动作。下面这个简单的例子在演讲和行动完成后打印出一些东西

    import SpriteKit
    import PlaygroundSupport
    import AVFoundation

    let start = CGPoint(x: 100, y: 50)
    let end = CGPoint(x: 200, y: 50)
    let radius: CGFloat = 20;
    let bounds = CGRect(x: 0, y: 0, width: 400, height: 200)
    let skview = SKView(frame: bounds)
    PlaygroundPage.current.liveView = skview
    PlaygroundPage.current.needsIndefiniteExecution = true

    class MyScene: SKScene,AVSpeechSynthesizerDelegate {
        var motionComplete = false
        var speechComplete = false
        let synth = AVSpeechSynthesizer();
        override func sceneDidLoad() {
            synth.delegate = self

            synth.speak(AVSpeechUtterance(string: "Ola"))

            let greenball = SKShapeNode(circleOfRadius: radius);
            greenball.position = start;
            greenball.fillColor = .green;

            let motionpath = CGMutablePath();
            motionpath.move(to: start)
            motionpath.addLine(to: end);
            let motion = SKAction.follow(motionpath, asOffset: false, orientToPath: true,duration: 2);
            greenball.run(motion) {
                print ("motion complete")
                self.motionComplete = true;
                self.syncUp()
            };
            self.addChild(greenball);
       }

        func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
            print ("speech complete")
            speechComplete = true;
            self.syncUp()
        }

        func syncUp() {
            if (motionComplete && speechComplete) {
                print ("speech and motion complete");
            }
        }

    }



    let scene = MyScene(size: CGSize(width: 400, height: 200));

    scene.scaleMode = SKSceneScaleMode.aspectFill
    scene.size = skview.bounds.size

    skview.presentScene(scene);
实际上,我正在尝试协调多个用户驱动和应用程序驱动的操作。是否有更好的技术来实现无bug同步