我正在使用SpriteKit的粒子发射器系统,在屏幕中心以玩家飞船为中心构建移动星空背景。
当玩家触摸屏幕区域时,我会计算角度并使玩家精灵朝那个方向旋转。
然而,当我将其应用于星空背景时,整个矩形都会旋转。但是我想要的是,单个粒子仅朝着新方向开始移动。
这就像旋转整张有点纸的纸张和让点只朝着新角度移动之间的区别。明白我的意思吗?
以下是我已经实现的部分,其中玩家正确旋转,但星空背景“像一整张纸一样旋转”:
当玩家触摸屏幕区域时,我会计算角度并使玩家精灵朝那个方向旋转。
然而,当我将其应用于星空背景时,整个矩形都会旋转。但是我想要的是,单个粒子仅朝着新方向开始移动。
这就像旋转整张有点纸的纸张和让点只朝着新角度移动之间的区别。明白我的意思吗?
以下是我已经实现的部分,其中玩家正确旋转,但星空背景“像一整张纸一样旋转”:
-(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];
}