Making a particle follow a path in spriteKit

心不动则不痛 提交于 2019-12-18 10:44:17

问题


I have created a particle and when I test it moving on Xcode's property window, it looks like this:

I have added this particle to a scene, made a circle and forced the particle to run that circle using this:

    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];

This is how it looks like. Like a block of white sugar candy. The node particle is following the path, but not the generated particles.

I have represented a circle in dashed so you can see the path it is following...

Any ideas?

thanks


回答1:


You sent the particle emitter to follow the path. If you want individual particles to run an action, use the emitter's particleAction property:

myParticle.particleAction = forever;


来源:https://stackoverflow.com/questions/18986098/making-a-particle-follow-a-path-in-spritekit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!