【问题标题】:Unable to create static HUD in Sprite Kit无法在 Sprite Kit 中创建静态 HUD
【发布时间】:2014-09-10 19:43:53
【问题描述】:

当我的主角(直升机飞行员)飞过地图时,我使用了 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);
    }
}

【问题讨论】:

    标签: objective-c sprite-kit hud


    【解决方案1】:

    好的,我刚刚发现解决方案非常基本且简单。 我刚刚在我的场景中添加了另一个 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的位置独立于飞行员的位置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多