在代码中:
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)
}
它显示了此行中的错误:
var shotLength:CGPoint = vecMult(方向,b:1000)
&#39;无法转换类型&#39; Int&#39;期望参数类型&#39; CGPoint&#39;
我一直在寻找,而且我不知道如何解决它。
有人可以帮助我吗?
答案 0 :(得分:1)
然后,你的问题是你有一个期望2分的功能,你传递了一个点和一个数字。您可能希望将vecMult重新定义为:
func vecMult(a:CGPoint, b:CGFloat) -> CGPoint {
return CGPoint(x:a.x * b, y:a.y * b)
}