Adding sound to SKAction.sequence

Hi,


I am trying to add sound to a sequence.


First, in GameScene.swift in func didMove (after creating the mySprite of course), I added the property to the sequence:


let demoAction = SKAction.move(to: CGPoint(x: 450, y: 300), duration: 3)

let growAction = SKAction.scale(to: 3, duration: 3)

let dialogueOne = SKAction.playSounfFileNamed("DialogueOne.m4a", waitForCompletion: false)

let sequence = SKAction.sequence([demoAction, growAction, dialogueOne])

mySprite.run(sequence)


...and this didn't work.


Then in GameScene.swift I added the property (globally):


let dialogueOne = SKAction.playSounfFileNamed("DialogueOne.m4a", waitForCompletion: false)


and called it at the end of the function:


let demoAction = SKAction.move(to: CGPoint(x: 450, y: 300), duration: 3)

let growAction = SKAction.scale(to: 3, duration: 3)

let sequence = SKAction.sequence([demoAction, growAction])

mySprite.run(sequence)

self.run(dialogueOne)


...this also didn't work.


I also imported AVFoundation in both GameViewController.swift and GameScene.swift btw - not sure if this was necessary.


The sequence works without the sound. How can I add sound to a sequence?


Thanks


h

Replies

Assuming SKAction.playSounfFileNamed is just a typo, your (pseudo?) code should work, I think, which points to your sound file itself. Check naming and try something else to confirm. Be sure to option-clean the build folder if you juggle assets/names.

Your first example is correct. Build it, install it on your device. Quit the app. Unplug your device. Launch the app again. See if it works.


Sometimes sounds get muted when the device is plugged in while testing.