我如何使用 didMoveToView 作为 initWithSize? [英] How do i use didMoveToView as initWithSize?
问题描述
我将 Xcode 更新到版本 6.从那以后,我一直无法使用以前使用 Objective C 在 Xcode 5 中编写的代码.
I updated Xcode to version 6. Since then I haven't been able to use the code that used to write in Xcode 5 using Objective C.
有一些新文件:GameScene.h 和 GameScene.m 和 GameScene.sks 而不是 MyScene.h 和 MyScene.m
There are some new files: GameScene.h and GameScene.m and GameScene.sks insteadf of MyScene.h and MyScene.m
他们加载:
-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */
}
而不是通常的
-(id) initWithSize: (CGSize)size {
}
我不能使用我以前在 didMoveToView 的 initWithSize 中编写的代码,它不能正常工作.如果我自己创建一个 initWithSize,它也不起作用.
I cannot use the code that i used to write in the initWithSize in the didMoveToView, it doesn't work as it should. And if i create a initWithSize myself, it doesn't work either.
请帮忙!:)
推荐答案
- didMoveToView:根据Apple 文档关于
SKScene
将在视图呈现场景后立即调用此方法,并且该方法旨在在子类中被覆盖. - didMoveToView: According the the Apple Documentation regarding
SKScene
this method will be called immediately after a scene is presented by a view and the method is intended to be overridden in a subclass. - initWithSize:这在初始化新场景对象时调用,并且只调用一次.
- initWithSize: This is called when initializing a new scene object and is only called once.
讨论
此方法旨在在子类中被覆盖.当场景即将由视图呈现时,您可以使用此方法为场景实现任何自定义行为.例如,您可以使用此方法来创建场景的内容.
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.
在 7.0 及更高版本中可用.
Available in 7.0 and later.
没有太多关于 initWithSize
的 Apple 文档,但我确实找到了另一个可能与您的问题有关的问题.
There isn't much Apple Documentation around initWithSize
but I did find a another question that maybe related to your question.
在哪里配置合适SpriteKit 中的 SKScene 内容? - 讨论配置 SKScene
内容的正确位置,所选答案比较了使用 initWithSize:
和didMoveToView:
.
Where is the right place to configure SKScene content in SpriteKit? - Discusses where is the correct place to configure your SKScene
content and the chosen answer compares the differences and pros of using either initWithSize:
and didMoveToView:
.
这篇关于我如何使用 didMoveToView 作为 initWithSize?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!