首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调整SpriteKit场景的大小

调整SpriteKit场景的大小
EN

Stack Overflow用户
提问于 2015-02-12 08:22:53
回答 1查看 469关注 0票数 1

我正在尝试使场景不同的大小基于用户使用的设备,这种方法一直很好,除了正确的时候,应用程序加载。例如,应用程序加载,屏幕大小不正确,但当我转到一个新场景时,屏幕大小就变成了它应该的大小。即使你回到开始的场景,它也会是正确的大小。它只在应用程序第一次加载时关闭,直到您转到新场景。这里是代码,任何帮助都将不胜感激。

代码语言:javascript
复制
- (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];
}
EN

回答 1

Stack Overflow用户

发布于 2015-02-12 10:00:13

默认情况下,视图是以纵向加载的,所以即使应用程序应该在横向运行,也可能会使用纵向模式的坐标。这是一种已知的行为。所以,如果你在横向模式下运行你的应用,这可能是一个问题。

在调用viewWillLayoutSubviews方法时,视图的大小将是正确的。

尝试使用viewWillLayoutSubviews而不是viewDidLoad:

代码语言:javascript
复制
 - (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];
        }


}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28467165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档