myParticleEmitter怪异(在0.0处创建工件),同时从A点绘制到B点

时间:2015-08-13 07:07:40

标签: sprite-kit

这里有点奇怪,我有一个粒子发射器添加到SKShapeNode (粒子应该遵循这条线)

然而当它确实时它还有一些粒子系统位于0,0 我把它移动了一点,以便你可以更好地看到它

对此可能发生的任何想法?, 我将发布下面的代码,但我仍然无法找到任何东西,我已经测试了其他纹理设置setStrokeTexture - 这条线正在制作某种偷偷摸摸的额外部分 - 但是没有看起来很好....并且在它们之间创建一条线精灵......

LinkWithNumberClass中的

// SKSpriteNode SKPhysicsContactDelegate

if (isUsingParticles == YES) {

    //create new line
    SKShapeNode*lineNode02 = [SKShapeNode node];
    lineNode02.lineWidth = 10;
    lineNode02.name = @"lineNode";

    //clear line of colour
    lineNode02.fillColor = [SKColor clearColor];
    lineNode02.strokeColor = [SKColor clearColor];

    //create the path the line follows (line joins two sprites)
    CGMutablePathRef pathToDraw = CGPathCreateMutable();
    CGPathMoveToPoint(pathToDraw, NULL, spriteA.position.x, spriteA.position.y);
    CGPathAddLineToPoint(pathToDraw, NULL, spriteB.position.x, spriteB.position.y);
    lineNode02.path = pathToDraw;
    [self addChild:lineNode02];

    //Add Particles 
    myParticlePath = [[NSBundle mainBundle] pathForResource:_parName ofType:@"sks"];
    myParticleEmitter = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
    [self addChild:myParticleEmitter];

     CGFloat distancebtween = SDistanceBetweenPoints(spriteA.position, spriteB.position);
    myParticleEmitter.particlePositionRange = CGVectorMake( particleLength,0 );
    myParticleEmitter.position = CGPointMake(distancebtween/2, +10);
    self->myParticleEmitter.targetNode = self.scene;

    int particleTime = 3;
     SKAction *followTrack =
     [SKAction followPath:pathToDraw
     asOffset:YES
     orientToPath:YES
     duration:particleTime];

     SKAction *forever = [SKAction repeatActionForever:followTrack];
     self->myParticleEmitter.particleAction = forever;
}

在游戏图层

    -(void)addStaticLinkedSpriteWithParticles
{
    twoSpritesWithParticlesBridge =
    [[LinkWithNumber alloc]initWithlinkSpriteA:@"Object"
                                       spriteB:@"Object"
                             andPlistAnimation:@"Aniamtions"
                                   distbetween:100
                                  hasParticles:YES
                                ParticlesNamed:@"Fire"];
      [self addChild:self->twoSpritesWithParticlesBridge];
}

谢谢:) 娜塔莉。

enter image description here

1 个答案:

答案 0 :(得分:0)

最后我开始工作,根本不需要画线。

  • 在SpriteA上创建粒子系统位置
  • 找到之间的距离 两个精灵(为了获得粒子的长度)
  • 调整发射器属性中粒子的长度
  • 重新定位 粒子使它们在两个精灵之间居中

        if (isUsingParticles == YES) {
    
    //create particles
    myParticlePath = [[NSBundle mainBundle] pathForResource:_parName ofType:@"sks"];
    myParticleEmitter = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
    [self addChild:myParticleEmitter];//try moving it to the line node
    
    //find length needed for particles
     CGFloat distancebtween = SDistanceBetweenPoints(spriteA.position, spriteB.position);
    
    //Adjust length of particles
    myParticleEmitter.particlePositionRange = CGVectorMake( particleLength,0 );
    
    //center particles between the two sprites
    myParticleEmitter.position = CGPointMake(spriteA.position.x+distancebetween/2, spriteA.position.y);
    myParticleEmitter.targetNode = self.scene;
    

    }

希望它可以帮助别人:)