2016-04-19 2 views
0

'予想引数の型に' int型の型の値を変換できません':コードにするCGPoint '

のvar shotLength:するCGPoint = vecMult(方向それは、この行でエラーを示し

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) 
} 

、B:1000)

『予想引数の型を『int型の型の値を変換できません』するCGPoint』私は検索してきたと私はそれを修正する方法がわからない

誰かが私を助けることができますか?

+0

エラーは「vecMult」の定義にあるように見えますが、あなたはそれを含めていないので、本当の問題が何であるかは分かりません。 –

+0

は、私はあなたがこれに言及していると思う: FUNC vecMult(:するCGPoint、B:するCGPoint) - >するCGPoint { リターンCGPointMake(a.x * b.x、a.y * b.y) } – norm

答えて

1

あなたの問題は、あなたが2点を期待し、それにポイントと数を渡しているということです。

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

はい、そうです。私はそれに気付かなかった...ありがとう!!!!! – norm

+0

@normあなたの質問に答える答えを受け入れることを忘れないでください。これはあなたの質問が解決されたことを示します。 – rmaddy

関連する問題