0

私の SpriteKit シーンでは、ユーザーは指で線を引くことができるはずです。下の画像のように、ラインが長い場合、FPS が 4 ~ 6 に下がり、ラインが多角形になり始めます。

ここに画像の説明を入力

myline( )を描くには、このようSKShapeNode*にタッチの動きを集めます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];
    }
}

この問題を解決するにはどうすればよいですか? 後続のすべての行はすべてポリゴンのみであるため、fpsが非常に低く、タッチのサンプリングレートも自動的に非常に低くなるためだと思います...

テストでは iPad 3 を使用したことに注意してください (私のアプリは iOS7 を搭載した iPad 2 モデルで動作する必要があります)

4

1 に答える 1

3

常に new を作成しないSKShapeNodesでください。速度低下の原因となっているバグがあります。代わりに、1つだけを使用しSKShapeNode(または束を作成して再利用し)、パスに新しい情報を追加します(したがって、常にバックグラウンドにマイラインを追加する必要はありません)

別:

パスのレンダリングに1 つのコミュニティを使用し、を でテクスチャにSKSkapeNode変換し、シェイプ ノードの代わりにこの新しいテクスチャで を追加します。SKShapeNodeview.textureFromNodeSKSpriteNode

于 2016-08-19T13:05:15.523 に答える