我在 Xcode 中创建了一个粒子发射器,它有很长的轨迹。当我将它移动到粒子生成器内部时,它会在我的鼠标路径之后留下一条轨迹。
关于我的目标的一些背景信息: 在我的 spriteKit 游戏中,用户在屏幕上拖动手指以拍摄移动的物体。我正在尝试创建“子弹时间”效果,当当前手指位置接触到对象时,对象会减慢并突出显示。当手指停止移动或弹药耗尽时,将触发 touchesEnded 方法,射击所有突出显示的对象。目前,我有他们行进的路径显示为使用 SKShapeNode 和 CGPath 绘制到屏幕上的一条线,但我希望用发射器轨迹突出显示轨迹。
在 touches started 方法中,我创建了一个圆形 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; 像这篇文章让粒子跟随 spriteKit 中的路径建议但是发射器根本没有出现。
如果我将particleAction 设置为followPath 它也不会留下痕迹。
在我的代码中,您可以看到我已经注释掉了一些行,基本上我已经尝试了所有我能想到的 targetNode 和particleAction 组合。
关于如何让发射器在我的手指路径上留下痕迹的任何建议?
谢谢