Reputation: 264
I've created a CCB file as a sprite: MySprite.ccb, with its Custom class set to MySprite.
If I don't want to place it into a layer in SpriteBuilder, but rather initialise objects from it and add them to the scene in Xcode, how do I do that?
What I've tried:
Added the following to the end of application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
in AppDelegate:
[CCBReader load:@"MySprite"];
And added this to didLoadFromCCB
in my scnene:
MySprite *newSprite = [[MySprite alloc] init];
newSprite.position = CGPointMake(250, 100);
[_physicsNode addChild:newSprite];
but that doesn't seem to work.
By the way, everything else is working fine, i.e. everything that's been placed in the scene in SpriteBuilder is working as expected.
Upvotes: 0
Views: 1127
Reputation: 3012
You just load your object with CCBReader
directly.
And use a cast for XCode
not to complain.
MySprite *newSprite = (MySprite *)[CCBReader load:@"MySprite"];;
newSprite.position = CGPointMake(250, 100);
[_physicsNode addChild:newSprite];
Upvotes: 2