1

我创建了一个 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];

PS _entityNode 是一个 SKNode,它同时添加了 ball 和 SKEmitterNode 火。它又是一个名为 _worldNode 的 SKNode 的子节点。_worldNode 是 self 的孩子(这是一个 SKScene)。这个 _worldNode 是一个翻转后的 (0, 0) 坐标从左下角开始。

4

1 回答 1

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.
于 2015-12-10T19:04:07.737 回答