【发布时间】:2014-08-26 14:02:55
【问题描述】:
我正在尝试制作一个没有填充的 SKShapeNode,但我找不到仅使用我绘制的线条制作 cgpath 的方法,我通过添加填充颜色并尝试使用其他 cgpath 参数来查看是否它没有填充,但它可以工作,这里的目标是只使用用户绘制的上下文创建一个 skshapenode,然后将一个物理体分配给用户绘制的线条或形状。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
touch1 = [touches anyObject];
location1 = [touch1 locationInNode:self];
pathTodraw = CGPathCreateMutable();
CGPathMoveToPoint(pathTodraw, nil, location1.x, location1.y);
sprite = [SKShapeNode node];
sprite.path = pathTodraw;
NSArray *colors = @[[UIColor blackColor],[UIColor redColor],[UIColor cyanColor]];
NSUInteger colorindex = arc4random() %colors.count;
sprite.strokeColor =[UIColor blueColor];
sprite.lineWidth = 3.0f;
sprite.fillColor = [colors objectAtIndex:colorindex];
[self addChild:sprite];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
touch2 = [touches anyObject];
location2 = [touch2 locationInNode:self];
CGPathAddLineToPoint(pathTodraw, nil, location2.x, location2.y);
sprite.path = pathTodraw;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
sprite.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:pathTodraw];
sprite.physicsBody.dynamic = YES;
sprite.physicsBody.affectedByGravity = YES;
}
-(void)update:(CFTimeInterval)currentTime {
if([self children].count>5){
SKAction *remove = [SKAction sequence:@[[SKAction waitForDuration:2.0],[SKAction fadeAlphaTo:0 duration:1.0],[SKAction removeFromParent]]];
[sprite runAction:remove];
[self removeAllChildren];
}
}
【问题讨论】:
-
当您不想让 SKShapeNode 填充路径时,为什么要将填充颜色设置为不透明的颜色?
标签: ios objective-c core-graphics sprite-kit cgpath