2015-12-09 21 views
1

我創建了一個SKEmitterNoder(標準Fire.sks模板)&將它添加到一個名爲ball的SKSpriteNode中。事情是,我按照教程&的方式跟隨了iOS Games的教程,他們教我創建平鋪地圖的方式,實質上是在初始化時將它們翻轉,以便(0,0)將位於屏幕的左下角& NOT top left 。我認爲這影響了我的SKEmitterNode targetNode屬性,因爲當球在場景中移動時,火焰發射器節點的方向完全相反。有人能告訴我該怎麼做才能改變這種情況嗎?我無法改變世界參數,所以我需要改變SKEmitterNode軌跡的東西,以便它實際上正確地跟隨球節點。這是我目前的代碼:SKEmitterNode targetNode路徑被反轉

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

P.S. _entityNode,其中球& SKEmitterNode火添加,是一個SKNode。這又是SKNode的一個名爲_worldNode的孩子。 _worldNode是自己的孩子(這是SKScene)。這個_worldNode是翻轉後有(0,0)座標從左下角開始的。

回答

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.