iPhone 5s SpriteKit 画怪 [英] iPhone 5s SpriteKit drawing oddities

查看:17
本文介绍了iPhone 5s SpriteKit 画怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 iPhone 5s 的像素分辨率为 640 x 1136,点分辨率为 320 x 568(用于向后兼容非 Retina 设备).

I understand that the iPhone 5s has a pixel resolution of 640 x 1136 and a point resolution of 320 x 568 (for backward compatibility with non-Retina devices).

当我使用 SpriteKit 时,问题/困惑/奇怪似乎出现了.示例:

The problem/confusion/oddity seems to come in when I'm working with SpriteKit. Example:

我正在从左下角 (0, 0) 到右上角(宽度、高度)画一条线.结果是这条线几乎画了一半.事实上,当我打印出屏幕尺寸时,它应该是 320 x 568.所以我决定从 (0, 0) 绘制到 (width * 2, height * 2).当然,这打印出 640 x 1136.

I'm drawing a line from bottom-left corner (0, 0) to top-right corner (width, height). The result was that the line was drawn almost halfway. And indeed when i print out the screen size, it should 320 x 568. So i decided to draw from (0, 0) to (width * 2, height * 2). And of course, this printed out 640 x 1136.

所以奇怪的是:尽管我是从一个角到角的对角线绘制,但实际上,它不是,是从一个角到另一个角绘制的.

So the oddity is this: Even though I'm drawing from what should be a diagonal line corner to corner, it is not, in actuality, being drawn from corner to corner.

注意事项:

 - I'm getting the width & height values from self.value.frame.size.
 - The diagonal line seems to draw just fine using any of the iPad simulators.

有什么想法吗?

推荐答案

不管怎样,这就是我得到好结果的方法:

Anyways here is how I got good results:

只需打开一个新项目并尝试以下操作:

Just open up a new project and try this:

在您的 GameViewContrller 中使用 viewWillLayoutSubviews 而不是使用 viewDidLoad.

In your GameViewContrller instead of using viewDidLoad use viewWillLayoutSubviews.

这是 Rob Mayoff 关于 viewDidLoadviewWillLayoutSubviews.

Here is a good explanation by Rob Mayoff about methods like viewDidLoad and viewWillLayoutSubviews.

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    // 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.

    if(!skView.scene){
        GameScene *scene = [GameScene sceneWithSize:skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;

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

所以现在在场景类的 didMoveToView 方法中,画一条线:

So now in your didMoveToView method in scene class, just draw a line :

    SKShapeNode *yourline = [SKShapeNode node];
    CGMutablePathRef pathToDraw = CGPathCreateMutable();
    CGPathMoveToPoint(pathToDraw, NULL, 0.0, 0.0);
    CGPathAddLineToPoint(pathToDraw, NULL, self.frame.size.width,self.frame.size.height);
    yourline.path = pathToDraw;
    [yourline setStrokeColor:[UIColor redColor]];
    [self addChild:yourline];
    CGPathRelease(pathToDraw);

阅读这篇关于init vs didMoveToView(阅读LearnCocos2D发表的评论).

Read this about init vs didMoveToView (read comments posted by LearnCocos2D).

差不多就这些了,希望对你有帮助.

So this is pretty much it, and I hope it helps.

这篇关于iPhone 5s SpriteKit 画怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆