How to use didMoveToView as initWithSize?

I upgraded Xcode to version 6. Since then, I have not been able to use the code that was used to write to Xcode 5 using Objective C.

There are several new files: GameScene.h and GameScene.m and GameScene.sks instead of MyScene.h and MyScene.m

They are loaded using:

-(void)didMoveToView:(SKView *)view {

/* Setup your scene here */

}

instead of the usual

-(id) initWithSize: (CGSize)size {

}

I can not use the code that I used to write to initWithSize in the didMoveToView file, it does not work properly. And if I create initWithSize myself, it doesn't work either.

Please, help! :)

+4
source share
3 answers

. , . , .

7.0 .

  • initWithSize: .

Apple initWithSize, , .

SKScene SpriteKit? - , SKScene, initWithSize:, didMoveToView:.

+1

-(void)didMoveToView:(SKView *)view ; - , , , Gamescene.m

0

SKS, initWithSize, . initWithCoder.

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{

    if (self = [super initWithCoder:aDecoder]) {
        // do stuff
    }

    return self;
}

About the initWith question ... vs didMoveToView. It depends on what you want. Init is intended to be initialized, but you should know that self.view is nil when initializing the scene (read the SO link provided by @Popeye).

0
source

Source: https://habr.com/ru/post/1570828/


All Articles