gpt4 book ai didi

objective-c - 我如何将 didMoveToView 用作 initWithSize?

转载 作者:搜寻专家 更新时间:2023-10-30 19:47:29 26 4
gpt4 key购买 nike

我将 Xcode 更新到版本 6。从那时起,我就无法使用以前使用 Objective C 在 Xcode 5 中编写的代码。

有一些新文件:GameScene.h 和 GameScene.m 以及 GameScene.sks 而不是 MyScene.h 和 MyScene.m

他们加载:

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

/* Setup your scene here */

}

而不是通常的

-(id) initWithSize: (CGSize)size {

}

我无法在 didMoveToView 的 initWithSize 中使用我以前编写的代码,它无法正常工作。如果我自己创建一个 initWithSize,它也不起作用。

求助!:)

最佳答案

  • didMoveToView: 根据 Apple Documentation关于 SKScene,此方法将在 View 呈现场景后立即调用,并且该方法旨在在子类中被覆盖。

Discussion

This method is intended to be overridden in a subclass. You can use this method to implement any custom behavior for your scene when it is about to be presented by a view. For example, you might use this method to create the scene’s contents.

Available in 7.0 and later.

  • initWithSize:初始化新场景对象时调用,仅调用一次。

没有多少Apple Documentation around initWithSize但我确实发现了另一个可能与您的问题相关的问题。

Where is the right place to configure SKScene content in SpriteKit? - 讨论配置 SKScene 内容的正确位置,选择的答案比较使用 initWithSize:didMoveToView: 的区别和优点.

关于objective-c - 我如何将 didMoveToView 用作 initWithSize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27897710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com