屏幕的实际尺寸大于我看到的目标C Xcode

时间:2015-07-17 11:31:47

标签: ios objective-c iphone xcode

当我在Xcode上创建一个新项目并使用游戏模板时,我得到了这个太空飞船游戏。我只是制作了一个简单的代码来查看它是否可以添加元素,但似乎屏幕的实际大小比我看到的要大。当我在x和y = 0或x和y = 10上绘制SKSpirtenode时,它不在屏幕上,它位于屏幕外的某个位置。当我让球反弹时,球从屏幕上移开然后回来,所以看起来某个地方已经结束但是我想解决这个问题。我不想使用特定的数字来设置屏幕,因为我希望我的应用程序也可以在iPhone 6和iPhone 5上运行。另外,我想让它适用于纵向和横向模式。

这是我的代码,我只是添加一个抽象对象。

这是我的视图controller.m

    @implementation SKScene (Unarchive)

+ (instancetype)unarchiveFromFile:(NSString *)file {
    /* Retrieve scene file path from the application bundle */
    NSString *nodePath = [[NSBundle mainBundle] pathForResource:file ofType:@"sks"];
    /* Unarchive the file to an SKScene object */
    NSData *data = [NSData dataWithContentsOfFile:nodePath
                                          options:NSDataReadingMappedIfSafe
                                            error:nil];
    NSKeyedUnarchiver *arch = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    [arch setClass:self forClassName:@"SKScene"];
    SKScene *scene = [arch decodeObjectForKey:NSKeyedArchiveRootObjectKey];
    [arch finishDecoding];

    return scene;
}

@end

@implementation GameViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;
    /* Sprite Kit applies additional optimizations to improve rendering performance */
    skView.ignoresSiblingOrder = YES;

    // Create and configure the scene.
    GameScene *scene = [GameScene unarchiveFromFile:@"GameScene"];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    // Present the scene.
    [skView presentScene:scene];
}


- (NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

@end

gamescene.m

#import "GameScene.h"

@implementation GameScene


-(void)didMoveToView:(SKView *)view {
    /* Setup your scene here */
    self.backgroundColor = [SKColor colorWithRed:0.29 green:0.75 blue:.99 alpha:1];
    SKSpriteNode *platform = [SKSpriteNode spriteNodeWithColor:[UIColor brownColor] size:CGSizeMake(100, 20)];
    platform.position = CGPointMake(50, 100);
    [self addChild:platform];

}


-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
}

@end

我读过我可以添加类似

的内容

scene = GameScene(self.view.frame.size)

但我不知道在哪里,我无法找到。

如果你能帮助我,我很高兴!

0 个答案:

没有答案