我正在尝试使场景不同的大小基于用户使用的设备,这种方法一直很好,除了正确的时候,应用程序加载。例如,应用程序加载,屏幕大小不正确,但当我转到一个新场景时,屏幕大小就变成了它应该的大小。即使你回到开始的场景,它也会是正确的大小。它只在应用程序第一次加载时关闭,直到您转到新场景。这里是代码,任何帮助都将不胜感激。
- (void)viewDidLoad
{
[super viewDidLoad];
iphone4x = 1.2;
iphone4y = 1.4;
iphone5x = 1.1;
iphone5y = 1.18;
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = NO;
skView.showsNodeCount = NO;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;
CGSize newSize;
if(iPhone4) {
newSize = CGSizeMake(skView.bounds.size.width * iphone4x, skView.bounds.size.height * iphone4y);
}
if (iPhone5) {
newSize = CGSizeMake(skView.bounds.size.width * iphone5x, skView.bounds.size.height * iphone5y);
}
if (iPhone6) {
newSize = CGSizeMake(skView.bounds.size.width, skView.bounds.size.height);
}
if(iPhone6Plus) {
}
// Create and configure the scene.
SKScene *scene = [MainMenu sceneWithSize:newSize];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}发布于 2015-02-12 10:00:13
默认情况下,视图是以纵向加载的,所以即使应用程序应该在横向运行,也可能会使用纵向模式的坐标。这是一种已知的行为。所以,如果你在横向模式下运行你的应用,这可能是一个问题。
在调用viewWillLayoutSubviews方法时,视图的大小将是正确的。
尝试使用viewWillLayoutSubviews而不是viewDidLoad:
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
skView.showsDrawCount = YES;
//skView.showsQuadCount = YES;
skView.showsPhysics = YES;
skView.ignoresSiblingOrder = YES;
//you have to check if scene is initialised because viewWillLayoutSubviews can be called more than once
if(!skView.scene){
// Create and configure the scene.
//instead of this from your code
//SKScene *scene = [MainMenu sceneWithSize:newSize];
//use this line
MainMenu * scene = [MainMenu sceneWithSize:newSize];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}https://stackoverflow.com/questions/28467165
复制相似问题