OGeek|极客世界-中国程序员成长平台

标题: ios - SpriteKit 背景不适合 iPhone 6 plus 上的屏幕 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:59
标题: ios - SpriteKit 背景不适合 iPhone 6 plus 上的屏幕

我正在使用缩放模式填充来加载背景大小为 640x1136 的场景,如下所示:

SKView * skView = (SKView *)self.view;
skView.ignoresSiblingOrder = YES;

MainMenu *scene = [MainMenu sceneWithSize: self.view.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;

[skView presentScene:scene];

然后我在屏幕内加载背景:

    SKSpriteNode *menuBg = [SKSpriteNode spriteNodeWithImageNamed"mainBg"];
    menuBg.anchorPoint = CGPointZero;
    menuBg.position = CGPointZero;
    [self addChild:menuBg];

我预计背景会填满屏幕,但它不会调整大小以填满屏幕。我只拿着@2x 背景图片 - 我做错了什么?



Best Answer-推荐答案


您没有将节点定位在场景的中心,因此无法使用 Aspect Fill 缩放模式正确缩放。

试试这个:

menuBg.anchorPoint = CGPointMake(0.5, 0.5);
menuBg.position = CGPointMake(self.size.width/2, self.size.height/2)

它将 anchor 设置在节点的中心,并将节点定位在场景的中心。

关于ios - SpriteKit 背景不适合 iPhone 6 plus 上的屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32033942/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4