使用SpriteKit中的SKEmitterNode和粒子创建跟踪

Evi*_*gis 8 particles sprite-kit sknode skemitternode

我试图让它变成这样一个粒子,只要玩家被移动,我就会跟随玩家.我试图复制的效果就像你在网站上,并且他们有一些跟随你的鼠标的对象.我尝试通过使粒子移动玩家所做的数量来做到这一点,但它没有再现预期的效果.有什么建议?我的代码:

声明粒子

NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"trail" ofType:@"sks"];
self.trailParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
self.trailParticle.position = CGPointMake(0,0);
[self.player addChild:self.trailParticle];
Run Code Online (Sandbox Code Playgroud)

移动方法

 -(void)dragPlayer: (UIPanGestureRecognizer *)gesture {

         if (gesture.state == UIGestureRecognizerStateChanged) {

              //Get the (x,y) translation coordinate
              CGPoint translation = [gesture translationInView:self.view];

              //Move by -y because moving positive is right and down, we want right and up
              //so that we can match the user's drag location (SKView rectangle y is opp UIView)
              CGPoint newLocation = CGPointMake(self.player.position.x + translation.x, self.player.position.y - translation.y);
              CGPoint newLocPart = CGPointMake(self.trailParticle.position.x + translation.x, self.trailParticle.position.y - translation.y);

              //Check if location is in bounds of screen
              self.player.position = [self checkBounds:newLocation];
              self.trailParticle.position = [self checkBounds:newLocPart];
              self.trailParticle.particleAction = [SKAction moveByX:translation.x y:-translation.y duration:0];
              //Reset the translation point to the origin so that translation does not accumulate
              [gesture setTranslation:CGPointZero inView:self.view];

         }

    }
Run Code Online (Sandbox Code Playgroud)

Vac*_*ias 15

试试这个:

1)如果您的发射器位于场景中,请使用此发射器的属性targetNode并将其设置为场景.这意味着粒子不会是发射器的孩子,但你的场景应该留下痕迹..

不确定这是否正确(我在C#中这样做):

self.trailParticle.targetNode = self; // self as Scene
Run Code Online (Sandbox Code Playgroud)

还有一些额外的:

2)我认为你可以把你的发射器作为孩子附加到self.player上,这样它就会自动与你的玩家一起移动,然后就不需要了:

self.trailParticle.position = [self checkBounds:newLocPart];
self.trailParticle.particleAction = [SKAction moveByX:translation.x y:-translation.y duration:0];
Run Code Online (Sandbox Code Playgroud)

  • targetNode是我需要的.谢谢. (2认同)