1

I am trying to load a CCScene and then change some of it's properties before using the scene. When I try to change it's properties it says [CCScene setProperty] - unrecognized selector sent to instance, even though I casted the CCScene to the correct class with the public properties!

#import "MainScene.h"
#import "Gameplay.h"

@implementation MainScene
-(void)play:(CCButton *)sender{
    Gameplay *gameplay = (Gameplay *)[CCBReader loadAsScene:@"Gameplay"];
    NSLog(@"%@\n",[gameplay class]);
}
@end

This code outputs CCScene instead of outputting Gameplay. How do I fix this?

4

2 回答 2

3

这不是演员阵容的问题。如果您执行loadAsSceneCCBReader会将Gameplay.ccb根节点包装到场景中。 您可以在文档中阅读:

... 加载具有指定名称的 ccbi 文件并将其包装在 CCScene 节点中。

如果您使用控制台打印此节点的子节点:

(lldb) po scene.children

您将得到以下结果:

<__NSArrayM 0x13a38720>(
  <Gameplay = 0x13a3f8a0 | Name = >
)

这显示了您的游戏类是如何包装到一个CCScene. 如果要访问Gameplay节点,则需要访问的第一个子节点CCScene

    Gameplay *gameplay = (Gameplay *)[[CCBReader loadAsScene:@"GameplayScene"] children] [0];

随意使用不同的解决方案,它不会在一条线上完成所有工作。

于 2014-04-20T11:47:15.480 回答
0

或者,您可以使用

SceneClass *sceneInstance = [CCBReader load:NSStringFromClass([SceneClass class])];

这导致:

(lldb) po sceneInstance
<SceneClass = 0x8270b70 | Name = >
于 2014-04-20T22:04:13.657 回答