在SpriteKit中让粒子沿着路径移动

17

我创建了一个粒子,当我在Xcode的属性窗口测试其移动时,它看起来像这样:

enter image description here

我将此粒子添加到场景中,制作了一个圆,并强制粒子沿着该圆运行,使用以下代码:

    NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"particle" ofType:@"sks"];
    SKEmitterNode *myParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
    [self addChild:myParticle];

    CGPathRef circle = CGPathCreateWithEllipseInRect(CGRectMake(0,0,400,400), NULL);

    SKAction *followTrack = [SKAction followPath:circle asOffset:NO orientToPath:YES duration:1.0];

    SKAction *forever = [SKAction repeatActionForever:followTrack];

    [myParticle runAction:forever];

它看起来像这样。像一块白糖果块。节点粒子跟随路径移动,但生成的粒子不是。

我用虚线表示了一个圆,以便您可以看到它所遵循的路径...

输入图像说明

有什么想法吗?

谢谢


3
如果有人卡住了,请尝试添加myParticle.targetNode = self;。 - DogCoffee
嗨@SpaceDog,能帮我一下吗?https://dev59.com/3Ynca4cB1Zd3GeqP8kXJ - user1872384
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
13

你已经派遣粒子发射器沿着路径移动。如果你想让每个粒子运行一个动作,请使用发射器的particleAction属性:

myParticle.particleAction = forever;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,