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?
This is not a problem of the cast. If you peform
loadAsScene
theCCBReader
will wrap the Gameplay.ccb root node into a scene. You can read that in the documentation:If you use the console to print the children of this node:
You will get following result:
This shows how your gameplay class is wrapped into a
CCScene
. If you want to access theGameplay
node you need to access the first child of theCCScene
:Feel free to use a different solution that doesn't do all the work in one line.