GKScene SpriteKit错误:[SKScene setEntities:]:无法识别的选择器发送到实例

时间:2018-03-14 16:31:55

标签: xcode sprite-kit entities gameplay-kit

我有一个代码可以很好地导入GameplayKit,我可以像这样得到GKScene:

GKScene * scene = [GKScene sceneWithFileNamed:@"GameScene1"];

然后,我将此问题发送到GameScene,这样可以扩展正常的SKScene

GameScene1 * scene1 = (GameScene1 *)scene.rootNode;

然后我收到错误[SKScene setEntities:]: unrecognized selector sent to instance 当我尝试获取这样的实体时:

scene1.entities = [scene.entities mutableCopy];

GameScene1扩展GameSceneGameScene.h已正确声明此属性。这是我的(部分)GameScene.h

@interface GameScene : SKScene <SKPhysicsContactDelegate>
@property (nonatomic) NSMutableArray<GKEntity *> *entities;
@end

我的GameScene1.h很短,只有几个导入,它会扩展GameScene,如下所示:

@interface GameScene1 : GameScene

您知道为什么XCode不会确认entities属性并为其分配值吗?

1 个答案:

答案 0 :(得分:0)

您应该子类GKScene而不是entities来访问属性SKScene

@interface GameScene : GKScene <SKPhysicsContactDelegate>

@end