在spriteKit中有粒子发射器跟踪跟随手指路径

我在Xcode中创建了一个具有相当长的路径的粒子发射器。 当我将它移动到粒子生成器内部时,它会沿着我的鼠标路径留下一条线索。

关于我的目标的一些背景信息:在我的spriteKit游戏中,用户在屏幕上拖动手指来拍摄移动的物体。 我正在尝试创建一个“子弹时间”效果,其中对象减速并在当前手指位置接触它们时突出显示。 当手指停止移动或者弹药耗尽时,会触发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; 喜欢这个post让一个粒子按照spriteKit中的路径建议但是然后发射器根本没有出现。

如果我将particleAction设置为followPath,它也不会留下痕迹。

在我的代码中你可以看到我已经注释掉了一些行,基本上我已经尝试了我能想到的targetNode和particleAction的每个组合。

关于如何让发射器在手指路径上留下痕迹的任何建议?

谢谢

我认为这段代码就是你所需要的;

 - (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; } } 

实际上pathEmitter.targetNode = self; 当你的物体移动时,它会让你有一个粒子留下痕迹,我没有看到为什么它不适合你的原因,因为我已经很久以前一直在使用这种方法,检查你的位置专门为方法touchesMoved