-(voID) dIDMovetoVIEw:(SKVIEw *) vIEw {/* Scene set up in here */}
与旧方法相反:
-(ID) initWithSize:(CGSize) size { if (self = [super initWithSize:size]{ /* Scene set up in here */ }}
我知道新方法(与视图控制器中的更改一样)用于帮助管理xCode 6中新增的.sks文件的导入.但是,如果我不想使用新的,我很好奇作为.sks文件的“storyboard”类型格式,我还应该使用新方法吗?或者我应该将方法更改回initWithSize方法并删除.sks文件?
解决方法 应该使用Init方法进行初始化,但请记住,在init内部,视图总是为零.因此,任何需要视图的代码都必须移动到 didMoveToView方法(在视图呈现场景后立即调用).关于Xcode 6中的initWithSize …默认情况下,场景是从.sks文件加载的.因此,initWithSize实际上从未被调用过.而是调用initWithCoder:
- (instancetype)initWithCoder:(NSCoder *)aDecoder{ if (self = [super initWithCoder:aDecoder]) { // do stuff } return self;}
因此初始化initWithSize中的任何内容都不会有任何影响.如果您决定删除.sks文件并以“旧”方式创建场景,则可以在视图控制器中执行以下 *** 作:
- (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 sceneWithSize:self.vIEw.bounds.size]; scene.scaleMode = SKScenescaleModeAspectFill; // Present the scene. [skVIEw presentScene:scene];}
之后,您可以使用initWithSize进行初始化.
请注意,在vIEwDIDLoad中,视图的最终大小可能尚未知晓,而使用vIEwWillLayoutSubvIEws可能是正确的选择.阅读更多here.
正确实现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; //vIEwWillLayoutSubvIEws can be called multiple times (read about this in docs ) so we have to check if the scene is already created if(!skVIEw.scene){ // Create and configure the scene. GameScene *scene = [GameScene sceneWithSize:self.vIEw.bounds.size]; scene.scaleMode = SKScenescaleModeAspectFill; // Present the scene. [skVIEw presentScene:scene]; }}
SWIFT代码:
overrIDe func vIEwWillLayoutSubvIEws() { super.vIEwWillLayoutSubvIEws() if let scene = GameScene.unarchiveFromfile("GameScene") as? GameScene { // Configure the vIEw. let skVIEw = self.vIEw as SKVIEw skVIEw.showsFPS = true skVIEw.showsNodeCount = true skVIEw.showsPhysics = true skVIEw.showsDrawCount = true /* Sprite Kit applIEs additional optimizations to improve rendering performance */ skVIEw.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ if(skVIEw.scene == nil){ scene.scaleMode = .AspectFill scene.size = skVIEw.bounds.size skVIEw.presentScene(scene) } }}总结
以上是内存溢出为你收集整理的ios – 何时在xCode 6.4中使用带有SpriteKit的didMoveToView或initWithSize全部内容,希望文章能够帮你解决ios – 何时在xCode 6.4中使用带有SpriteKit的didMoveToView或initWithSize所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)