Assign the SKAction returned when running play() on an SKAudioNode?

137 Views Asked by At

The docs seem to suggest that running play on an SKAudioNode returns an SKAction

play() Creates an action that tells an audio node to start playback.

class func play() -> SKAction

So my wee logic tells me I can get at this returned Action, and assign it to a variable or constant like this:

var mySoundAction = mySoundNode.run(SKAction.play())

But Xcode tells me I'm an idiot and have no idea what I'm doing when I try to do this:

self.run(mySoundAction)

It tells me it's unable to convert a type of void to that of an SKAction.

What am I doing wrong? How deluded am I in my goals to have an action name for something like this?

1

There are 1 best solutions below

2
On BEST ANSWER
SKAction.play()

returns an SKAction, and

mySoundNode.run(SKAction.play())

runs that action on mySoundNode. The run() method returns Void ("nothing"), so with

var mySoundAction = mySoundNode.run(SKAction.play())

you run the "play" action on the node and assign () to var mySoundAction. What you perhaps meant is

var mySoundAction = SKAction.play()
// ... 
self.run(mySoundAction)