Я пытаюсь добавить аудио в последовательность в swift.Я попытался добавить свойство звука глобально, а затем вызвать его в функции, но звук не воспроизводился в конце последовательности действий анимации:
import AVFoundation
import SpriteKit
class GameScene: SKScene {
let dialogueOne = SKAction.playSoundFileNamed("MySound.m4a", waitForCompletion: false)
override func didMove(to view: SKView) {
// Add instance of SKSSpriteNode, make the scene position from its lower left corner
self.anchorPoint = .zero
// Instantiate constant, set colour and size & position relative to parent node (the scene), and add childNode
let mySprite = SKSpriteNode(color: .blue, size: CGSize(width: 50, height: 50))
mySprite.position = CGPoint(x: 150, y: 150)
self.addChild(mySprite)
// Create constant for action instance and run
let demoAction = SKAction.move(to: CGPoint(x: 450, y: 300), duration: 3)
let growAction = SKAction.scale(to: 3, duration: 3)
let rotateAction = SKAction.rotate(byAngle: 5, duration: 5)
let sequence = SKAction.sequence([demoAction, growAction, rotateAction])
mySprite.run(sequence)
self.run(dialogueOne)
}
}
Итак, я попытался добавить SKAction.playSoundFileNamed
внутри функции и вызывая ее в последовательности, но так же, как и выше, воспроизводится последовательность анимации, но звук отсутствует:
override func didMove(to view: SKView) {
// Add instance of SKSSpriteNode, make the scene position from its lower left corner
self.anchorPoint = .zero
// Instantiate constant, set colour and size & position relative to parent node (the scene), and add childNode
let mySprite = SKSpriteNode(color: .blue, size: CGSize(width: 50, height: 50))
mySprite.position = CGPoint(x: 150, y: 150)
self.addChild(mySprite)
// Create constant for action instance and run
let demoAction = SKAction.move(to: CGPoint(x: 450, y: 300), duration: 3)
let growAction = SKAction.scale(to: 3, duration: 3)
let rotateAction = SKAction.rotate(byAngle: 5, duration: 5)
let dialogueOne = SKAction.playSoundFileNamed("MySound.m4a", waitForCompletion: false)
let sequence = SKAction.sequence([demoAction, growAction, rotateAction, dialogueOne])
mySprite.run(sequence)
}
Есть идеи, как мне это сделать?