无法使用类型'(距离:(CGVector,fadeInWithDuration:Double))的参数列表调用'moveDistance'(Cannot invoke &

编程入门 行业动态 更新时间:2024-10-28 12:25:38
无法使用类型'(距离:(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)

更多推荐

本文发布于:2023-08-04 01:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:距离   参数   类型   列表   CGVector

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!