【问题标题】:SKEmitterNode targetNode path following is invertedSKEmitterNode targetNode 路径如下反转
【发布时间】:2015-12-09 08:27:38
【问题描述】:

我创建了一个 SKEmitterNoder(标准 Fire.sks 模板)并将其添加到一个名为 ball 的 SKSpriteNode 中。问题是,我按照教程的 iOS 游戏教程以及他们教我创建平铺地图的方式,基本上是在初始化时翻转它们,这样 (0, 0) 将位于屏幕的左下角而不是左上角.我认为这会影响我的 SKEmitterNode targetNode 属性,因为当球在场景中移动时,火发射器节点会朝完全相反的方向移动。有人能告诉我该怎么做才能改变吗?我无法更改世界参数,所以我需要一些可以改变 SKEmitterNode 轨迹的东西,以便它实际上正确地跟随球节点。这是我当前的代码:

NPCBall *ball   = [[NPCBall alloc] initWithBallType:BallTypeRed andName:@"Ball Red"];
ball.position   = CGPointMake(x + w/2, y + h/2);
ball.zPosition  = -104.0;
[_entityNode addChild:ball];

//Create a random Vector.dx & dy for the NPC. This will apply a random impulse to kick start NPC non-stop movement.
[ball.physicsBody applyImpulse:CGVectorMake([self randomVectorGeneration].dx, [self randomVectorGeneration].dy)];

//Create a particle for the ball (fire).
SKEmitterNode *emitFire = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"Particle_Fire" ofType:@"sks"]];
emitFire.position       = CGPointMake(ball.position.x, ball.position.y);
emitFire.targetNode = ball;
[_entityNode addChild:emitFire];

附: _entityNode,球和 SKEmitterNode 火都添加到,是一个 SKNode。它又是一个名为 _worldNode 的 SKNode 的子节点。 _worldNode 是 self 的孩子(这是一个 SKScene)。这个 _worldNode 是翻转后的 (0, 0) 坐标从左下角开始的节点。

【问题讨论】:

    标签: ios objective-c sprite-kit skemitternode


    【解决方案1】:

    my'n 的一位朋友找到了解决此问题的方法。我在这里发布它,以防有人也有一个倒置的平铺地图,其中 (0, 0) 坐标位于场景的左下角。

        //Create a ball sprite.
        SKSpriteNode *ball = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(20, 20)];
        ball.position   = CGPointMake(_worldNode.frame.size.width/2, _worldNode.frame.size.height/2);
        [_entityNode addChild:ball]; //<--_entityNode is also an SKNode. It's a child of _worldNode.
        ball.zPosition  = -104.0;
    
        //Create a random Vector.dx & dy for the NPC. This will apply a random impulse to kick start NPC non-stop movement.
        [ball.physicsBody applyImpulse:CGVectorMake([self randomVectorGeneration].dx, [self randomVectorGeneration].dy)];
    
    
        //Create a particle effect for the ball.
        SKEmitterNode *emitFire = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"Particle_Fire" ofType:@"sks"]];
        emitFire.name           = @"Fire Emitter";
        emitFire.targetNode     = _worldNode; //<-- This is the demon. Make the emitter follow this SKNode since it moves when the ball moves. Everything in my game is a child of _worldNode.
        [ball addChild:emitFire]; //Add the emitter to the ball.
    

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 2021-12-12
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多