简体   繁体   English

'无法将'Int'类型的值转换为预期的参数类型'CGPoint'

[英]'Cannot convert value of type 'Int' to expected argument type 'CGPoint'

In the code: 在代码中:

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {

    self.runAction(SKAction.playSoundFileNamed("ball.mp3", waitForCompletion: false))

    let touch = touches.first
    var location:CGPoint = touch!.locationInNode(self)

    var torpedo: SKSpriteNode = SKSpriteNode(imageNamed: "heartbullet")
    torpedo.position = player.position

    torpedo.physicsBody = SKPhysicsBody(circleOfRadius: torpedo.size.width/2)
    torpedo.physicsBody?.dynamic = true
    torpedo.physicsBody?.categoryBitMask = photoTorpedoCategory
    torpedo.physicsBody?.contactTestBitMask = alienCategory
    torpedo.physicsBody?.collisionBitMask = 0
    torpedo.physicsBody?.usesPreciseCollisionDetection = true

    var offset:CGPoint = vecSub(location, b: torpedo.position)
    if (offset.y < 0){
        return
    }

    self.addChild(torpedo)

    var direction:CGPoint = vecNormalize(offset)

    var shotLength:CGPoint = vecMult(direction, b: 1000)
    var finalDestination:CGPoint = vecAdd(shotLength, b: torpedo.position)

    let velocity = 568/1
    let moveDuration:Float = Float(self.size.width) / Float(self.size.width) / Float(velocity)

    var actionArray:[SKAction] = [SKAction]()
    actionArray.append(SKAction.moveTo(finalDestination, duration: NSTimeInterval(moveDuration)))
    actionArray.append(SKAction.removeFromParent())

    torpedo.runAction(SKAction.sequence(actionArray))
}


func vecAdd(a:CGPoint, b:CGPoint)->CGPoint{
    return CGPointMake(a.x + b.x, a.y + b.y)
}

func vecSub(a:CGPoint, b:CGPoint)->CGPoint{
    return CGPointMake(a.x - b.x, a.y - b.y)
}

func vecMult(a:CGPoint, b:CGPoint)->CGPoint{
    return CGPointMake(a.x * b.x, a.y * b.y)
}

func vecLenght(a:CGPoint)->CGFloat{
    return CGFloat(sqrtf(CFloat(a.x)*CFloat(a.x)+CFloat(a.y)*CFloat(a.y)))
}

func vecNormalize(a:CGPoint)->CGPoint{
    let length:CGFloat = vecLenght(a)
    return CGPointMake(a.x / length, a.y / length)
}

It shows the error in this line: 它在此行中显示错误:

var shotLength:CGPoint = vecMult(direction, b: 1000) var shotLength:CGPoint = vecMult(direction,b:1000)

'Cannot convert value of type 'Int' to expected argument type 'CGPoint' '无法将'Int'类型的值转换为预期的参数类型'CGPoint'

I've been searching and i don't know how to fix it. 我一直在搜索,但不知道如何解决。

Can someone help me? 有人能帮我吗?

Then, your problem is that you have a function that expects 2 points and you're passing it a point and a number. 然后,您的问题是您有一个期望得到2分的函数,并且正在传递给它一个分和一个数字。 You probably want to redefine vecMult as: 您可能想将vecMult重新定义为:

func vecMult(a:CGPoint, b:CGFloat) -> CGPoint {
    return CGPoint(x:a.x * b, y:a.y * b)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法转换 &#39;CGPoint!&#39; 类型的值到预期的参数类型 &#39;UnsafeMutablePointer<CGPoint> &#39; - Cannot convert value of type 'CGPoint!' to expected argument type 'UnsafeMutablePointer<CGPoint>' 无法将Int类型的值转换为预期的参数类型Bool - Cannot convert value of type Int to expected argument type Bool 无法在Swift 3中将字符串类型的值转换为预期的参数类型int - cannot convert value of type string to expected argument type int in swift 3 无法转换类型为“任何对象!”的值 到预期的参数类型“ Int” - cannot convert value of type 'Anyobject!' to expected argument type 'Int' 无法将类型“ Int”的值转换为预期的参数类型“ String”? - Cannot convert value of type 'Int' to expected argument type 'String'? 无法将类型&#39;(_,_,_)-&gt;()&#39;的值转换为预期的参数类型&#39;Int64&#39; - Cannot convert value of type '(_, _, _) -> ()' to expected argument type 'Int64' 无法将 Int 类型的值转换为预期的参数类型“...” - Cannot convert value of type Int to expected Argument type '...' 无法将时间&#39;Int&#39;的值转换为Swift 2中的预期参数类型&#39;NSPropertyListReadOptions&#39; - Cannot convert value of time 'Int' to expected argument type 'NSPropertyListReadOptions' in Swift 2 无法将类型“ Int”的值转换为预期的参数类型“ UnsafeMutablePointer <Int32> ! - Cannot convert value of type 'Int' to expected argument type 'UnsafeMutablePointer<Int32>!' 无法将&#39;Int&#39;类型的值转换为预期的参数类型&#39;(inout UnsafeMutableBufferPointer &lt;_&gt;,inout Int)throws - &gt; Void&#39; - Cannot convert value of type 'Int' to expected argument type '(inout UnsafeMutableBufferPointer<_>, inout Int) throws -> Void'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM