[英]'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.