ios - 让粒子发射器轨迹跟随 spriteKit 中的手指路径

标签 ios ios7 sprite-kit particle-system skemitternode

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

关于我的目标的一些背景信息: 在我的 spriteKit 游戏中,用户在屏幕上拖动他们的手指来射击移动的物体。我正在尝试创建一个“子弹时间”效果,当当前手指位置接触到对象时,对象会减慢并突出显示。当手指停止移动或弹药用完时,将触发 touchesEnded 方法射击所有突出显示的对象。目前,我使用 SKShapeNode 和 CGPath 将它们行进的路径显示为在屏幕上绘制的一条线,但我希望使用发射器轨迹突出显示轨迹。

在 touches begind 方法中,我创建了一个圆圈 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 的所有组合。

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

谢谢

最佳答案

实际上是 pathEmitter.targetNode = self;是一种让你有一个粒子在你的物体移动时留下痕迹的方法,我看不出它对你不起作用的任何原因因为我很久以前就一直在使用这种方法,检查一下你的位置专门用于方法 touchesMoved

关于ios - 让粒子发射器轨迹跟随 spriteKit 中的手指路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22645904/

相关文章:

ios - UIDocumentInteractionController 禁止在某些应用程序中打开

iOS SDK 将照片与附加数据一起发布到 Web 服务

ios - 如何更改 ios7 中非事件标签栏图标的颜色?

swift - 在 Xcode 中播放声音,同时从应用程序播放音乐

ios - 使物理体响应场但不响应其他物理体

ios - 在 UIViewController 中添加 Storyboard 作为 subview

ios - Obj-C - didSelectRowAtIndexPath 未触发?

xcode - NSBundle UIImage nil iOS 7 特定

在 ios7 中覆盖 drawRect 失败

swift - 两个 SpriteNode 之间的接触问题