- 締切済み
swiftのsprite kitで質問です(2)
続きです。 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch: AnyObject in touches { let location = touch.locationInNode(self) let midX = CGRectGetMidX(self.frame) let midY = CGRectGetMidY(self.frame) let area2 = (location.x - midX) / (location.y - (midY - (midY / 5.0))) if location.y > midY - (midY / 5.0) { if area2 >= -1 && area2 <= 1 { let area1 = ((location.x - midX) / (location.y - midY)) if location.y - midY <= 0 && location.x - midX <= 0 { print("left") } else if location.y - midY < 0 && location.x - midX > 0 { print("right") } else if area1 < -0.3 { print("left") } else if area1 >= -0.3 && area1 <= 0.3 { print("center") } else if area1 > 0.3 { print("right") } myImage.position = location var position = CGPointZero position = self.convertPointFromView((touches.first?.locationInView(view))!) let path = CGPathCreateMutable() CGPathMoveToPoint(path, nil, position.x, position.y) //CGPathAddCurveToPoint(path, nil, position.x , position.y , midX, midY, midX, midY) if let theNode = self.childNodeWithName("curve") { theNode.removeFromParent() } let shapeNode = SKShapeNode(path: path) shapeNode.name = "curve" self.addChild(shapeNode) } } } } //打球種 SegmentedControlの値が変わったときに呼び出される. func segconChanged1(segcon: UISegmentedControl){ let path = CGPathCreateMutable() CGPathMoveToPoint(path, nil, position.x, position.y) let midX = CGRectGetMidX(self.frame) let midY = CGRectGetMidY(self.frame) guard let shapeNode = childNodeWithName("curve") as? SKShapeNode else { return } switch segcon.selectedSegmentIndex { case 0: CGPathAddCurveToPoint(path, nil, position.x , position.y , midX, midY, midX, midY) case 1: CGPathAddCurveToPoint(path, nil, (position.x + midX) / 2.0 , position.y , midX, midY, midX, midY) case 2: CGPathAddCurveToPoint(path, nil, (position.x + midX) / 2.0 , (position.y + (midY / 1.5)), midX, midY, midX, midY) default: print("Error") } shapeNode.lineWidth = 1.0 } //結果 SegmentedControlの値が変わったときに呼び出される. func segconChanged(segcon: UISegmentedControl){ // shapeNodeを取得 guard let shapeNode = childNodeWithName("curve") as? SKShapeNode else { return } switch segcon.selectedSegmentIndex { case 0: shapeNode.strokeColor = UIColor.redColor() case (1...4): shapeNode.strokeColor = UIColor.greenColor() case (5...6): shapeNode.strokeColor = UIColor.yellowColor() default: print("Error") } shapeNode.lineWidth = 1.0 } } 以上、よろしくお願いします。
- みんなの回答 (1)
- 専門家の回答
みんなの回答
- Lchan0211b
- ベストアンサー率61% (573/930)
こちらは、何の質問の続きなのか元の質問のURLをきちんと示して、こちらに回答を入れてもらわないよう配慮すべきだと思います。 (元の質問) http://bekkoame.okwave.jp/qa9109743.html