无法在Sprite Kit中创建静态HUD

时间:2014-09-10 10:33:53

标签: objective-c sprite-kit hud

因为当我飞过地图时我使用了一个centerOnNode方法来跟踪我的主角(一个直升机飞行员),我想不出有任何可能性将一个带有点和高分的非移动HUD置于其上方。屏幕。

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */

    SKNode *myWorld = [SKNode node];
    self.currentMyWorld = myWorld;
    [self addChild:myWorld];

    SKLabelNode *score = [SKLabelNode labelNodeWithFontNamed:@"Verdana-BoldItalic"];
    score.fontSize = 25;
    score.fontColor = [SKColor yellowColor];
    score.zPosition = 4;
    self.pointHUD = score;
    [myWorld addChild:score];

    }
    return self;
}


#pragma mark - didSimulatePhysics

- (void)didSimulatePhysics
{

    [self centerOnNode: [self childNodeWithName: @"//pilot"]]; 
}

- (void) centerOnNode: (SKNode *) node
{
    CGPoint cameraPositionInScene = [node.scene convertPoint:node.position
                                                    fromNode:node.parent];

    if (self.currentPilot.position.x < -400 && self.currentPilot.position.y > -400 && self.currentPilot.y < 400){node.parent.position = CGPointMake(400, node.parent.position.y - cameraPositionInScene.y); 
    }else if (self.currentPilot.position.x < -400 && self.currentPilot.position.y < -400){node.parent.position = CGPointMake(400, 400);
    }else if (self.currentPilot.position.x < -400 && self.currentPilot.position.y > 400){node.parent.position = CGPointMake(400, -400);
    }else if (self.currentPilot.position.x > 400 && self.currentPilot.position.y < -400){node.parent.position = CGPointMake(-400, 400); 
    }else if (self.currentPilot.position.x >400 && self.currentPilot.position.y > 400){node.parent.position = CGPointMake(-400, -400);

    }else if ((self.currentPilot.position.x > -400 && currentPilot.position.y < -400) || (self.currentPilot.x < 400 && self.currentPilot.y < -400))
    {node.parent.position = CGPointMake(node.parent.position.x - cameraPositionInScene.x,400);

    }else if ((self.currentPilot.position.x > -400 && self.currentPilot.position.y > 400) || (self.currentPilot.position.x < 400 && self.currentPilot.position.y > 400))
    {node.parent.position = CGPointMake(node.parent.position.x - cameraPositionInScene.x,-400);

    }else if (self.currentPilot.position.x > 400 && self.currentPilot.position.y > -400 && self.currentPilot.position.y < 400){node.parent.position = CGPointMake(-393, node.parent.position.y - cameraPositionInScene.y); 
    }else if (self.currentPilot.position.x > -400 && self.currentPilot.position.y < 400 && self.currentPilot.position.y > -400 && self.currentPilot.position.y < 400){node.parent.position = CGPointMake(node.parent.position.x - cameraPositionInScene.x,node.parent.position.y - cameraPositionInScene.y);
    }
}

1 个答案:

答案 0 :(得分:4)

好的,我只是想通了解决方案非常简单。 我刚在场景中添加了另一个SKNode。

    SKNode *HUD = [SKNode node];
    self.HudNode = HUD;
    [self addChild:HUD];

    SKLabelNode *highscore = [SKLabelNode labelNodeWithFontNamed:@"Verdana-BoldItalic"];
    highscore.fontSize = 25;
    highscore.fontColor = [SKColor yellowColor];
    highscore.zPosition = 4;
    self.highScoreLabel = highscore;
    [HudNode addChild:highscore];

现在HUD的位置独立于飞行员的位置