Reputation: 149
I am trying to make a SKSpriteNode bounce across the screen, but when I run it, I get an error (on the first line):
cannot invoke 'runAction' with an argument of type 'SKAction!'
I have no idea what is causing this. I've pasted the entire runAction code below:
self.runAction(SKAction.sequence(
[ SKAction.repeatAction(SKAction.sequence(
[
{self.updatePath()},
SKAction.followPath(path.CGPath, duration: 3.0)
]), count: numberOfBounces),
{actionMoveDone()}
]
))
Thanks in advance!
Upvotes: 2
Views: 2330
Reputation: 12753
Changing an action's argument will have no effect on the action once it has started. As such, your actions will use the same, original path repeatedly during the execution of the series of actions. Also, you are running the action on self
, which I assume is an SKScene
subclass, when followPath
actions are typically run on sprites.
If you want a sprite to follow a different path during each iteration, you will need to create a new action. One way to do that is to create a function that updates the path, creates a new action, and then calls itself at the completion of the current action. For example,
func createAction() {
updatePath()
sprite.runAction(SKAction.followPath(path.CGPath, asOffset: false, orientToPath: true, duration: 3.0),
completion: {
if (++self.count < numberOfBounces) {
self.createAction()
}
else {
// Run this after running the action numberOfBounces times
self.actionMoveDone()
}
}
)
}
and start the series by calling the function
createAction()
Upvotes: 5
Reputation: 8130
Your code is a little messy.
First of all you dont really need that first sequence. It makes more sense to use a completion block.
Secondly, why the curly braces inside your inner sequence? Is self.updatePath() an SKAction? A sequence can only be an array of SKActions. If it's an SKAction you don't need any curly braces, otherwise you need to use SKAction.runBlock({})
So based off your code.. I'm thinking this is what you're trying to do..
self.runAction(
SKAction.repeatAction(
SKAction.sequence([
// guessing self.updatePath isnt an SKAction, but I don't know
SKAction.runBlock({ self.updatePath() }),
SKAction.followPath(path.CGPath, duration: 3.0)
]), count: numberOfBounces),
completion:{
// also not sure if this is an SKAction, or something else
actionMoveDone()
})
Upvotes: 4