Ron*_*huk 6 ios particle-system ios7 sprite-kit skemitternode
我在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; 喜欢这个帖子制作一个粒子跟随一个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;
    }
}
| 归档时间: | 
 | 
| 查看次数: | 3467 次 | 
| 最近记录: |