我在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;像这个帖子那样的,Making a particle follow a path in spriteKit建议,但是发射器根本就没有出现。
如果我将particleAction设置为followPath,它也不会留下任何痕迹。
在我的代码中,您可以看到我已经注释掉了一些行,基本上我已经尝试了我能想到的targetNode和particleAction的每一个组合。
关于如何让发射器在我的手指路径上留下痕迹,有什么建议吗?
谢谢
发布于 2014-07-16 09:39:57
我认为这个代码就是你所需要的;
- (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-11 00:36:07
实际上,pathEmitter.targetNode = self;是会让你有一个粒子在物体移动时留下轨迹的方法,我没有看到为什么它对你不起作用,因为我很久以前就使用过这个方法了,检查一下你的位置,特别是touchesMoved方法
https://stackoverflow.com/questions/22645904
复制相似问题