Bạn có thể sử dụng SKShapeNode để vẽ hình dạng trong bộ công cụ ma, nhưng mỗi SKShapeNode được giới hạn ở một màu đường kẻ (strokeColor) và một màu tô.
Tuy nhiên, bạn có thể tạo lớp con SKNode tùy chỉnh chứa hai SKShapeNodes là trẻ em, mỗi lớp có strokeColors/fillColors khác nhau.
Something như thế này sẽ làm việc cho một SKNode tùy chỉnh mà vẽ một hình vuông với trái và đầu đỏ, phải và phía dưới màu xanh lá cây:
- (id) init {
if (self = [super init]) {
SKShapeNode* topLeft = [SKShapeNode node];
UIBezierPath* topLeftBezierPath = [[UIBezierPath alloc] init];
[topLeftBezierPath moveToPoint:CGPointMake(0.0, 0.0)];
[topLeftBezierPath addLineToPoint:CGPointMake(0.0, 100.0)];
[topLeftBezierPath addLineToPoint:CGPointMake(100.0, 100.0)];
topLeft.path = topLeftBezierPath.CGPath;
topLeft.lineWidth = 10.0;
topLeft.strokeColor = [UIColor redColor];
topLeft.antialiased = NO;
[self addChild:topLeft];
SKShapeNode* bottomRight = [SKShapeNode node];
UIBezierPath* bottomRightBezierPath = [[UIBezierPath alloc] init];
[bottomRightBezierPath moveToPoint:CGPointMake(0.0, 0.0)];
[bottomRightBezierPath addLineToPoint:CGPointMake(100.0, 0.0)];
[bottomRightBezierPath addLineToPoint:CGPointMake(100.0, 100.0)];
bottomRight.path = bottomRightBezierPath.CGPath;
bottomRight.lineWidth = 10.0;
bottomRight.strokeColor = [UIColor greenColor];
bottomRight.antialiased = NO;
[self addChild:bottomRight];
}
return self;
}
Như tôi đã nói rằng bản vẽ sẽ được lấp đầy với hai màu sắc. Làm thế nào tôi có thể điền vào dòng. Đó phải là một trong hai hình chữ nhật hoặc hình khác. Tôi thừa nhận rằng đây là cách để vẽ nhưng tôi chỉ hỏi làm thế nào tôi có thể điền vào nó? – Programmer
Tôi không hiểu ý bạn là gì. Bạn có thể tải lên một hình ảnh về những gì bạn muốn nó trông như thế nào? – Greg
Tôi đã đăng mẫu hình ảnh tại đây. [link] (http://postimg.org/image/je24gs8yv/) – Programmer