Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c SKLabelNode定位未按预期工作_Objective C_Sprite Kit_Sknode_Sklabelnode - Fatal编程技术网

Objective c SKLabelNode定位未按预期工作

Objective c SKLabelNode定位未按预期工作,objective-c,sprite-kit,sknode,sklabelnode,Objective C,Sprite Kit,Sknode,Sklabelnode,我正在做一个游戏,我需要实现顶部的酒吧,持有像分数和其他东西的细节 我的顶部栏应具有以下内容(从左到右): -一个50x50图标,根据级别而变化,但大小相同 -带有一些文本的标签,这些文本根据级别而变化 - ... 其他要素 问题是,当标签文本更改时,标签有时离图标太远,而其他时间则在图标上方(取决于文本长度) 我以为我懂定位,但显然我不懂 //create array for level text label levelTextArray = [[NSArray alloc] initWith

我正在做一个游戏,我需要实现顶部的酒吧,持有像分数和其他东西的细节

我的顶部栏应具有以下内容(从左到右): -一个50x50图标,根据级别而变化,但大小相同 -带有一些文本的标签,这些文本根据级别而变化 - ... 其他要素

问题是,当标签文本更改时,标签有时离图标太远,而其他时间则在图标上方(取决于文本长度)

我以为我懂定位,但显然我不懂

//create array for level text label
levelTextArray = [[NSArray alloc] initWithObjects:@"\"Uuu! Bubbles!\"",@"\"Noob\"",@"\"I’m getting it..\"",@"\"This is easy\"",@"\"Wha?\"",@"\"It’s ooon now!\"",@"\"Come on..\"",@"\"Dude…\"",@"\"You’re pushing it..\"",@"\"I’ll show you!!\"",@"\"AAAAAAA!!!\"",@"\"Holy Bubbles… \"",@"\"Ninja mode on!\"",@"\"I’m on fire!!\"",@"\"The wheel's spinning, but the hamsters dead. \"", nil];

//add level text label
levelTextLabel = [[SKLabelNode alloc] init];
levelTextLabel.text = levelTextArray[0];
levelTextLabel.position = CGPointMake(60, CGRectGetMidY(scoreImage.frame)+5);

levelTextLabel.fontColor = [UIColor colorWithRed:0/255.0f green:1/255.0f blue:0/255.0f alpha:1.0f];
levelTextLabel.fontName = @"Noteworthy-Light";
levelTextLabel.fontSize = 14.0;
[self addChild:levelTextLabel];
scoreImage是本例中的图标。另外..为了使图像完全显示在视图中,我将其定位如下:

  scoreImage = [[ SKSpriteNode alloc] initWithImageNamed:levelText];
    scoreImage.name = @"LevelImage";
    scoreImage.size = CGSizeMake(50, 50);
    scoreImage.position = CGPointMake(0+scoreImage.size.width/2, CGRectGetMaxY(self.frame)-scoreImage.size.height/2);
我觉得我在这里做错了什么

感谢您的帮助


另外,标签文本和图标图像会根据
-(void)update:(CFTimeInterval)currentTime{

中的级别进行更改,请尝试设置
SKLabelNode
水平对齐模式

levelTextLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;
默认值为
SKLabelHorizontalAlignmentModeCenter