![](/img/trans.png)
[英]Swift "Cannot invoke '-=' with argument list of type '(@lvalue CGFloat, $T7)'
[英]Cannot invoke '*' with an argument list of type '($T7, $T14)'
因此,嘗試從obj c轉到快速並出現此問題。
let offset = CGPointMake(location.x - bird.position.x, location.y - bird.position.y);
let length = sqrtf((Float)(offset.x * offset.x + offset.y * offset.y))
let direction = CGPointMake(offset.x / length, offset.y / length)
對於第三行,我得到了錯誤-無法使用類型為(($ T5,$ t10))的參數列表調用'/'。 我需要輸入強制類型轉換以及要解決的內容。 這里也是一樣
func moveSprite(sprite: SKSpriteNode) {
let amountToMove = CGPointMake(velocity.x * dt, velocity.y * dt)
}
這里的錯誤是-無法調用類型為(($ T7,$ t14)'的參數列表的'*'
現在,dt是一個NSTimeinterval,速度是一個CGPoint。 當我嘗試將投射速度鍵入兩倍時,我只會遇到另一個錯誤。 無法使用類型為(($ T9,$ t18)'的參數列表調用'init'
我需要在這里做什么來解決此問題。
您不能在Swift中混合使用數字類型。 您必須將length
強制為CGFloat。
let direction = CGPointMake(offset.x / CGFloat(length), offset.y / CGFloat(length))
另外,這一行不是Swift:
let length = sqrtf((Float)(offset.x * offset.x + offset.y * offset.y))
那是沒有意義的; 這不是您在Swift中的強制方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.