iPhone 5s SpriteKit drawing oddities

拈花ヽ惹草 提交于 2019-12-02 06:59:29
Whirlwind

Anyways here is how I got good results:

Just open up a new project and try this:

In your GameViewContrller instead of using viewDidLoad use viewWillLayoutSubviews.

EDIT: 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];
    }
}

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);

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!