Spritekit .sks文件中不会更改自定义类

时间:2016-10-25 06:50:47

标签: ios sprite-kit

我一直在使用SpriteKit,但无法解决我在.sks文件中使用自定义类的问题。下面是您在新创建的SpriteKit项目中找到的sceneDidLoad方法:

- (void)viewDidLoad {
[super viewDidLoad];

// Load 'GameScene.sks' as a GKScene. This provides gameplay related content
// including entities and graphs.
GKScene *scene = [GKScene sceneWithFileNamed:@"GameScene"];

// Get the SKScene from the loaded GKScene
GameScene *sceneNode = (GameScene *)scene.rootNode;

// Copy gameplay related content over to the scene
sceneNode.entities = [scene.entities mutableCopy];
sceneNode.graphs = [scene.graphs mutableCopy];

// Set the scale mode to scale to fit the window
sceneNode.scaleMode = SKSceneScaleModeAspectFill;

SKView *skView = (SKView *)self.view;

// Present the scene
[skView presentScene:sceneNode];

skView.showsFPS = YES;
skView.showsNodeCount = YES;
}

没什么太疯狂的 - 它只是加载一个名为GameScene的.sks文件,找到它的根节点(由于.sks中的自定义类被设置为GameScene类型),然后将其推送到屏幕上。 / p>

我遇到的问题是,当我更改此.sks文件和相关类时,根节点永远不会采用自定义类。 sceneWithFileNamed方法正在找到.sks文件,因为无效的名称将导致该方法返回nil,而它当前返回一个场景(但具有正常的SKScene根节点而不是我的自定义类)。当我尝试将场景实体分配给sceneNode时,这会导致我的项目崩溃,而sceneNode不是SKScene的内置属性。

这是我修改过的版本,仅包含两项修改:

- (void)viewDidLoad {
[super viewDidLoad];

// Load 'MenuScene.sks' as a GKScene. This provides gameplay related content
// including entities and graphs.
GKScene *scene = [GKScene sceneWithFileNamed:@"MenuScene"];

// Get the SKScene from the loaded GKScene
MenuScene *sceneNode = (MenuScene *)scene.rootNode;

// Copy gameplay related content over to the scene
sceneNode.entities = [scene.entities mutableCopy];
sceneNode.graphs = [scene.graphs mutableCopy];

// Set the scale mode to scale to fit the window
sceneNode.scaleMode = SKSceneScaleModeAspectFill;

SKView *skView = (SKView *)self.view;

// Present the scene
[skView presentScene:sceneNode];

skView.showsFPS = YES;
skView.showsNodeCount = YES;
}

这里是MenuScene.h文件:

#import <SpriteKit/SpriteKit.h>
#import <GameplayKit/GameplayKit.h>

@interface MenuScene : SKScene

@property (nonatomic) NSMutableArray<GKEntity *> *entities;
@property (nonatomic) NSMutableDictionary<NSString*, GKGraph *> *graphs;

@end

也许更有趣的是,我可以更改GameScene .sks的自定义类,但代码运行时似乎没有任何改变。

我错过了什么,或者自定义课程被打破了吗?

更新:我已经尝试将模块名称放在.sks检查器中自定义类下面的字段中,但它还没有解决。这是指向该解决方案的帖子的链接:https://forums.developer.apple.com/thread/25620

0 个答案:

没有答案