iPhone(iOS) SDKでゲーム(2)
今回は、ポリゴンの描画。
こんな感じで描画すると。
- (void)drawRect:(CGRect)rect {
CGContextRef c = UIGraphicsGetCurrentContext();
// CGContextRetain(c);
CGContextSetRGBFillColor (c, 0.0f, 0.0f, 1.0f, 1.0f);
CGContextSetRGBStrokeColor(c, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextSetLineWidth (c, 2.0f);
CGContextSetLineCap (c, kCGLineCapSquare); // kCGLineCapRound
CGContextMoveToPoint (c, 10.0f, 10.0f);
CGContextAddLineToPoint(c, 50.0f, 80.0f);
CGContextAddLineToPoint(c, 100.0f, 30.0f);
CGContextAddLineToPoint(c, 10.0f, 10.0f);
CGContextDrawPath(c, kCGPathFillStroke);
// CGContextStrokePath(c); // ラインのみ
// CGContextRelease(c);
}
▼CGContext Reference
http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html
