私のSpriteKitシーンでは、指で線を描くことができるはずです。SpriteKitで線を効率的に描画する方法
はmyline
(SKShapeNode*
)、私が収集描くために:私は、ラインが長い場合、FPSは4-6まで取得し、行は以下の画像のように、多角形の取得を開始し、作業溶液を持っていますこのようにNSMutableArray* noteLinePoints
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInNode:self.scene];
SKNode *node = [self nodeAtPoint:touchPoint];
if(noteWritingActive)
{
[noteLinePoints removeAllObjects];
touchPoint = [[touches anyObject] locationInNode:_background];
[noteLinePoints addObject:[NSValue valueWithCGPoint:touchPoint]];
myline = (SKShapeNode*)node;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if(myline)
{
CGPoint touchPoint = [[touches anyObject] locationInNode:_background];
[noteLinePoints addObject:[NSValue valueWithCGPoint:touchPoint]];
[self drawCurrentNoteLine];
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if(myline)
{
myline.name = @"note";
myline = nil;
}
NSLog(@"touch ended");
}
でのタッチの動きのポイントと私はこのように
- (CGPathRef)createPathOfCurrentNoteLine
{
CGMutablePathRef ref = CGPathCreateMutable();
for(int i = 0; i < [noteLinePoints count]; ++i)
{
CGPoint p = [noteLinePoints[i] CGPointValue];
if(i == 0)
{
CGPathMoveToPoint(ref, NULL, p.x, p.y);
}
else
{
CGPathAddLineToPoint(ref, NULL, p.x, p.y);
}
}
return ref;
}
- (void)drawCurrentNoteLine
{
if(myline)
{
SKNode* oldLine = [self childNodeWithName:@"line"];
if(oldLine)
[self removeChildrenInArray:[NSArray arrayWithObject:oldLine]];
myline = nil;
myline = [SKShapeNode node];
myline.name = @"line";
[myline setStrokeColor:[SKColor grayColor]];
CGPathRef path = [self createPathOfCurrentNoteLine];
myline.path = path;
CGPathRelease(path);
[_background addChild:myline];
}
}
を線を引きます3210
この問題を解決するにはどうすればよいですか?それ以降のすべての線はすべて多角形であるため、fpsが非常に低く、タッチのサンプリングレートも自動的に非常に低くなるので、私は思っています...
私はiPad 3を使用しました
シェイプノードのこの新しいテクスチャを
SKSpriteNode
を追加し、view.textureFromNode
でテクスチャにSKShapeNode
を変換しますとにかく、私はいつも同じSKShapeNodeを再利用しようとします。あなたの素早い答えをありがとう! – ddbNP、おそらく彼らはiOS 10のSKShapeNodesを修正するでしょう – Knight0fDragon
@ddb私はあなたのためにうまくいくかもしれない代替の答えを投稿しました – Knight0fDragon