我阅读了其他帖子,并将视图控制器viewdidload更改为:
(void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
}
我真的不确定问题是什么。这是我的代码:
(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
world=SKNode.node;
[self addChild:world];
self.anchorPoint= CGPointMake(0.5, 0.5);
SKSpriteNode *ground = [SKSpriteNode spriteNodeWithColor:[UIColor yellowColor] size: CGSizeMake(self.frame.size.width, 150)];
ground.position= CGPointMake(0, -self.frame.size.height/2+ ground.frame.size.width/2);
ground.physicsBody= [SKPhysicsBody bodyWithRectangleOfSize:ground.size];
ground.physicsBody.dynamic=NO;
NSLog(@"ground position: %f" , -self.frame.size.height/2+ ground.frame.size.width/2);
[world addChild:ground];
generator = [WorldGenerator generatorWithWorld:world];
[self addChild:generator];
[generator populate];
hero = [MLHero hero];
[world addChild:hero];
pointsLabel =[SKLabelNode labelNodeWithFontNamed:@"ChalkDuster"];
if (pointsLabel)
NSLog(@"true");
pointsLabel.fontColor=[SKColor redColor];
pointsLabel.fontSize=40;
pointsLabel.text=@"0";
pointsLabel.position= CGPointMake(200,200); //I have tried many different values and none seem to work, including setting to the width and height etc.
[self addChild:pointsLabel];
}
return self;
}