2017-02-17 15 views
0

は、私は、プレーヤーが円のためにタップされたゲームを、作成しています、と私は選手ではなく、円の四角をタップします。ここで円を正方形に切り替える方法は? -SpriteKit

しか使用SKShapeNode(rectOfSize:)はあなたのコードの代わりにSKShapeNode(circleOfRadius:)

残りの部分は正常に動作します

override func addBall(_ size: Int) { 
    let currentBall = SKShapeNode(circleOfRadius: CGFloat(size)) 
    let shape = SKShapeNode() 
    let viewMidX = view!.bounds.midX 
    let viewMidY = view!.bounds.midY 

    currentBall.fillColor = pickColor() 

    //Rectangle 
    shape.path = UIBezierPath(roundedRect: CGRect(x: 64, y: 64, width: 160, height: 160), cornerRadius: 50).cgPath 

    shape.fillColor = pickColor() 

    func randomBallPosition() -> CGPoint { 
     let xPosition = CGFloat(arc4random_uniform(UInt32((view?.bounds.maxX)! + 1))) 
     let yPosition = CGFloat(arc4random_uniform(UInt32((view?.bounds.maxY)! + 1))) 

     return CGPoint(x: xPosition, y: yPosition) 
    } 

    currentBall.position = randomBallPosition() 
    shape.position = randomBallPosition() 

    self.addChild(shape) 

    //Remove other balls and add the new one 
    if scoreCount != 0{ 
     if scoreCount == 1{ 
      self.addChild(score) 
      self.addChild(timeLeftLabel) 
      self.childNode(withName: "welcome")?.removeFromParent() 
     } 
     self.childNode(withName: "ball")?.run(getSmaller) 
     self.childNode(withName: "ball")?.removeFromParent() 
    } 
    currentBall.name = "ball" 

    self.addChild(currentBall) 
} 
+0

SpriteKitベースのたく使用UIBezierPath(rect: CGRect)はトリッキーですが、ドキュメントから少し助けを借りて、あなたが考えている、まさにやってのけることができます。 –

答えて

1

円をタップするための私のコードです。

EDIT:

あなたも代わりinit(roundedRect: CGRect, cornerRadius: CGFloat)

+0

だからlet shape = SKShapeNode(rectOfSize:CGFloat(size))を置くべきですか? – Jonathon

+0

はい、試してみてください。それが動作すれば私に知らせてください。 –

+0

それは、ドキュメントを読んでください。それはCGSizeその後CGSizeを提供必要がある場合「とは、基本的な質問をしていないと予想引数の型CGSize」 – Jonathon

関連する問題