7

Xcode で非常に長いトレイルを持つパーティクル エミッターを作成しました。パーティクル ジェネレーター内で移動すると、マウス パスに沿って軌跡が残ります。

私の目標に関する背景情報: 私の spriteKit ゲームでは、ユーザーは画面上で指をドラッグして動くオブジェクトを撃ちます。現在の指の位置がオブジェクトに触れると、オブジェクトの速度が低下してハイライトされる「Bullet Time」効果を作成しようとしています。指の動きが止まるか、弾薬がなくなると、 touchesEnded メソッドが起動され、ハイライトされたすべてのオブジェクトが撃たれます。現在、SKShapeNode と CGPath を使用して画面に描画された線として表示される移動パスがありますが、代わりにエミッタ トレイルでトレイルを強調表示したいと思います。

タッチ開始メソッドでは、指がどこに移動しても動き回る円の SpriteNode を作成します (物理衝突はパスではなく円に関連付けられます)。パーティクル トレイル エミッターをこの円に取り付けました。画面上で移動すると、円と一緒に移動しますが、軌跡は残りません。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInNode:self];

    pathToDraw = CGPathCreateMutable();
    startPoint = touchLocation;
    CGPathMoveToPoint(pathToDraw, NULL, touchLocation.x, touchLocation.y);

    lineNode = [SKShapeNode node];
    lineNode.path = pathToDraw;
    lineNode.lineWidth = 2;
    lineNode.zPosition = 110;
    lineNode.strokeColor = [SKColor whiteColor];
    [self addChild:lineNode];

    circle = [SKSpriteNode spriteNodeWithTexture:[animationsAtlas textureNamed:@"anim_countdown_9"]];
    circle.name = @"circle";
    circle.scale = 0.3;
    circle.alpha = 0.5;
    circle.zPosition = 110;
    circle.position = touchLocation;

    circle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:20];
    circle.physicsBody.categoryBitMask = weaponCategory;
    circle.physicsBody.dynamic = NO;
    circle.physicsBody.contactTestBitMask = billyCategory;
    circle.physicsBody.collisionBitMask = 0;

    [self addChild:circle];

    pathEmitter = [SKEmitterNode skt_emitterNamed:@"FollowPath"];
    //pathEmitter.position = circle.position;
    //pathEmitter.targetNode = self;
    //pathEmitter.scale = 0.2;
    //pathEmitter.zPosition = 60;
    [circle addChild:pathEmitter];
}

touchesMoved メソッドでは、それに応じて円を新しい位置に移動します

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {

UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInNode:self];

circle.position = currentPoint;

SKAction *wtf = [SKAction followPath:pathToDraw asOffset:NO orientToPath:YES duration:0.1];
//pathEmitter.position = currentPoint;
//[pathEmitter runAction:wtf];
//pathEmitter.particleAction = wtf;
pathEmitter.particleAction = [SKAction moveTo:currentPoint duration:1.0];

CGPathAddLineToPoint(pathToDraw, NULL, currentPoint.x, currentPoint.y);

lineNode.path = pathToDraw;

pathEmitter.targetNode = self;を設定してみました。この投稿のように、スプライトキットのパスに沿ってパーティクルを作成することをお勧めしますが、エミッタはまったく表示されません。

また、particleAction を followPath に設定すると、トレイルも残りません。

私のコードでは、いくつかの行をコメントアウトしたことがわかります。基本的に、私が考えることができる targetNode とparticleAction のすべての組み合わせを試しました。

エミッターが指のパスに跡を残す方法について何か提案はありますか?

ありがとう

4

2 に答える 2

3

実際には pathEmitter.targetNode = self; は、オブジェクトが移動するときに粒子が軌跡を残すようにするものです。私はこの方法をずっと前から使用しているため、機能しない理由はわかりません。確認してください特にメソッドtouchesMovedのためのあなたの位置

于 2014-07-11T00:36:07.760 に答える
1

このコードだけで十分だと思います。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInNode:self];


    circle = [SKSpriteNode spriteNodeWithTexture:[animationsAtlas textureNamed:@"anim_countdown_9"]];
    circle.name = @"circle";
    circle.scale = 0.3;
    circle.alpha = 0.5;
    circle.zPosition = 110;
    circle.position = touchLocation;

    circle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:20];
    circle.physicsBody.categoryBitMask = weaponCategory;
    circle.physicsBody.dynamic = NO;
    circle.physicsBody.contactTestBitMask = billyCategory;
    circle.physicsBody.collisionBitMask = 0;

    [self addChild:circle];

    pathEmitter = [NSKeyedUnarchiver unarchiveObjectWithFile: [[NSBundle mainBundle] pathForResource:@"FollowPath"ofType:@"sks"]];
    pathEmitter.position = CGPointMake(0, -60);
    [circle addChild:pathEmitter];

}


- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {

    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInNode:self];

    circle.position = currentPoint;

}

- (void)update:(CFTimeInterval)delta
{
    if (!pathEmitter.targetNode) {
        pathEmitter.targetNode = self;
    }
}
于 2014-07-16T09:39:57.547 に答える