新场景是根据其帧大小创建的,但每次都会变小。为什么?

New scene is created from its frame size but it keeps getting smaller each time. Why?

我正在写一个游戏,用户必须使用一些盘子来防止掉落的物体(石头)通过屏幕的按钮,每次点击都会在那个位置制作一个盘子,但他每次只能有 5 个盘子然后点击第六点消失了第一个盘子,同时创建了一个新盘子。 这是关于我的游戏机制如何运作的简要说明。

这是我的代码部分,它使用物理计算掉落的物体(精灵),如果它们超过 10 个,将显示游戏结束消息,代码将重新启动游戏,一个新游戏。要玩新游戏,我需要

-(void)didSimulatePhysics
{
    [self enumerateChildNodesWithName:@"rock" usingBlock:^(SKNode *node, BOOL *stop) {
        if (node.position.y < 0)
        {
            ScoreNum++;
            [node removeFromParent];
            score.text = [NSString stringWithFormat:@"%@ %li",ScoreMSG,(long)ScoreNum];
            if (ScoreNum > 10)
            {
                score.fontSize = 40;
                score.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
                score.text = @"Game Over!";            
                SKScene *spaceshipScene  = [[GameScene alloc] initWithSize:CGRectMake(0, 0,CGRectGetMaxY(self.frame),CGRectGetMaxX(self.frame)).size];                
                printf("%f %f",CGRectGetMidX(self.frame),CGRectGetMidX(self.frame));
                SKTransition *doors = [SKTransition doorsOpenVerticalWithDuration:0.25];
                [self.view presentScene:spaceshipScene transition:doors];
                ScoreNum = 0;         
            }
        }  
    }];
}

GameScene 像这样从 SKScene 继承而来

#import <SpriteKit/SpriteKit.h>
@interface GameScene : SKScene
@end

代码可以找到,但盘子(屏幕上的所有精灵)从侧面被挤压

下图是结果,第一次,第二次,第三次,我需要10个声望来包含3张图片,所以我不得不将它们全部合并为一张图片,给你。 https://www.imageupload.co.uk/images/2015/08/30/123.png 抱歉,由于我的声誉不够,我无法嵌入图片!

为什么我的每个场景都挤?

看起来你在 viewController.viewDidLoad 中设置了一个 scaleMode 来处理你的游戏场景,你的物理代码没有问题(在你的问题中)。

找找这样的东西scene.scaleMode = SKSceneScaleModeAspectFill 通常 SKScenes 会根据设备的屏幕尺寸自动缩放,由 SKScene 为您提供场景。

您图片中的场景显示场景具有完整且完整的覆盖,但它们被缩放了。

It is kind of hard to handle sprite size while do not controling scale. I suggest to get ride of every Scale Mode and remark them all and control the scale your self. if you are not going to zoom in/out as I believe it is the case in your game you just need to reset the scenes scale to 1 each time after each scene transition.