私はユーザーが指で線を描くことができるゲームを作っています。ウェブサイトにはたくさんのメソッドがあります。 UIView(UIKit)でCGContextを使用する方法と、SpriteKitでCGPathとSKShapeNodeを使用する方法の2つの方法を試しました。しかし後者ははるかに優れた品質を示しています。 CGContextを使用する最初のものは醜い荒いエッジを持っています。iOS CGContextを使用する描画線の品質は、SpriteKitのSKShapeNodeよりもはるかに悪いです。
次のスクリーンショットを参照してください。私はここでも両方のメソッドのコードの一部を添付しました(touchesMove
関数内)。
注:var ref = CGPathCreateMutable()
CGPathAddLineToPoint(ref, nil, currentPoint.x, currentPoint.y)
UIGraphicsBeginImageContext(self.frame.size)
let context = UIGraphicsGetCurrentContext()
tempImageView.image?.drawInRect(CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))
CGContextAddPath(context, ref)
// 3
CGContextSetLineCap(context, CGLineCap.Round)
CGContextSetLineWidth(context, brushWidth)
CGContextSetRGBStrokeColor(context, red, green, blue, 1.0)
CGContextSetBlendMode(context, CGBlendMode.Normal)
// 4
CGContextStrokePath(context)
// 5
UIGraphicsEndImageContext()
SpriteKitベースでSKShapeNode 注
var lineDrawing = SKShapeNode()
CGPathAddLineToPoint(ref, nil, location.x, location.y)
lineDrawing.path = ref
lineDrawing.lineWidth = 3
lineDrawing.strokeColor = UIColor.blackColor()
lineDrawing.alpha = 1.0
self.addChild(lineDrawing)
同じ品質のSKShapeNodeでUIViewに線を描画するにはどうすればよいですか? 、
UIGraphicsBeginImageContextWithOptions(self.frame.size, false, 0)
WithOptions
バージョン:
UIGraphicsBeginImageContext(self.frame.size)
あなたはこの代わりに使用する必要があります。
実際のパスのプリントがあります。私の推測では、それぞれに異なる数のパスがあるということです。 –