无法使用类型'(距离:(CGVector,fadeInWithDuration:Double))的参数列表调用'moveDistance'(Cannot invoke 'moveDistance' with an argument list of type '(distance: (CGVector, fadeInWithDuration: Double))')
运行SKAction方法但语法有些问题。 我从一开始就填写了Xcode 8代码完成告诉我但仍然没有运气的方式。
无法使用类型'(距离:(CGVector,fadeInWithDuration:Double))的参数列表调用'moveDistance'
a.swift
extension SKAction { class func moveDistance(distance:CGVector, fadeInWithDuration duration:TimeInterval) -> SKAction { let fadeIn = SKAction.fadeIn(withDuration: duration) let moveIn = SKAction.move(by: distance, duration: duration) return SKAction.group([fadeIn, moveIn]) } }b.swift
// legacy // //gameOverLayer?.runAction(SKAction.moveDistance(CGVectorMake(0, 100), fadeInWithDuration: 0.2))) // Swift 3 gameOverLayer?.run(SKAction.moveDistance(distance: (CGVector(dx: 0, dy: 100), fadeInWithDuration: 0.2)))过了一会儿,我意识到我添加了太多括号......是的noob。
Running an SKAction method but having some problems with the syntax. I started from the beginning and filled everything in the way that Xcode 8 code completion was telling me to but still no luck.
Cannot invoke 'moveDistance' with an argument list of type '(distance: (CGVector, fadeInWithDuration: Double))'
a.swift
extension SKAction { class func moveDistance(distance:CGVector, fadeInWithDuration duration:TimeInterval) -> SKAction { let fadeIn = SKAction.fadeIn(withDuration: duration) let moveIn = SKAction.move(by: distance, duration: duration) return SKAction.group([fadeIn, moveIn]) } }b.swift
// legacy // //gameOverLayer?.runAction(SKAction.moveDistance(CGVectorMake(0, 100), fadeInWithDuration: 0.2))) // Swift 3 gameOverLayer?.run(SKAction.moveDistance(distance: (CGVector(dx: 0, dy: 100), fadeInWithDuration: 0.2)))After hrs I realized I added 1 too many parenthesis ...yes noob.
最满意答案
你可以重构你的扩展方法,以便在调用它时更容易,如下所示:
extension SKAction { class func move(dx: CGFloat, dy: CGFloat, fadeIn duration: TimeInterval) -> SKAction { return SKAction.group([ SKAction.fadeIn(withDuration: duration), SKAction.move(by: CGVector(dx: dx, dy: dy), duration: duration) ]) } }用法:
SKAction.move(dx: 0, dy: 100, fadeIn: 0.2)You can refactor your extension method to make it easier for you when calling it as follow:
extension SKAction { class func move(dx: CGFloat, dy: CGFloat, fadeIn duration: TimeInterval) -> SKAction { return SKAction.group([ SKAction.fadeIn(withDuration: duration), SKAction.move(by: CGVector(dx: dx, dy: dy), duration: duration) ]) } }Usage:
SKAction.move(dx: 0, dy: 100, fadeIn: 0.2)更多推荐
发布评论