Change direction of existing particles

Viewed 1501

I'm using SpriteKit's Particle Emitter system to construct a moving star field in the background with the player's ship in the center of the screen.

When the player touches an area of the screen I calculate the angle and animate the player sprite turning that direction.

When I apply it to the star field, however, the entire rectangle the star field is painted on rotates. What I want, however, are for the individual particles to simply start moving in a new direction.

It's the difference between rotating an entire sheet of paper with dots all over it and merely having the dots move toward a new angle. Does that make sense?

Here's what I have so far with the player rotating correctly but the star field "rotating like a whole sheet of paper":

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    // Choose one of the touches to work with
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    CGPoint center = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));

    CGPoint offset = rwSub(location, center);

    SKEmitterNode *starfield = (SKEmitterNode *)[self childNodeWithName:@"starfield"];

    SKSpriteNode *player = (SKSpriteNode *)[self childNodeWithName:@"player"];

    SKAction *rotateNode = [SKAction rotateToAngle: (CGFloat)atan2(offset.y, offset.x) duration:0.5  shortestUnitArc:TRUE];
    [player runAction: rotateNode];

    SKAction *rotateStarfieldNode = [SKAction rotateToAngle: (CGFloat)(atan2(offset.y, offset.x) - M_PI_2) duration:0.5  shortestUnitArc:TRUE];
    [starfield runAction: rotateStarfieldNode];
}
3 Answers
Related