Chapter 3 actionMidMove error

(iBooks / ePub version, so left the page number out)

SKAction.move() has the following method signature:
let actionMidMove = SKAction.move(by: CGVector, duration: TimeInterval)

The code sample in the book reads as follows:
let actionMidMove = SKAction.moveBy(x: -size.width/2-enemy.size.width/2, y: -playableRect.height/2 + enemy.size.height/2, duration: 1.0)

This has the following compile errors:
-Expected expression in list of expressions
-Expected ‘;’ separator
Use of unresolved identifier ‘x’

Clearly there is some syntax error in the code, but I’m not sure how to define the vector here? Perhaps when the book was written the method had a different signature? It appears to me a CGPoint is being passed in when a CGVector is what is expected.

@abunur This is the SKAction class method signature that you should use over here in this case:

class func moveBy(x: CGFloat, y: CGFloat, duration: TimeInterval)

https://developer.apple.com/documentation/spritekit/skaction/1417722-moveby

Please let me know if you have any other questions or issues regarding the whole thing. Thank you!

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.