I am actually learning SpriteBuilder
which is really a great tool for me, but I am facing a trouble concerning including a CCNode
inside my scene (programmatically way).
So, I have a scene "Gameplay
" where my characters are implemented from other CCB
files.
Concerning the scenery, at first I put my map and some wall (for scene limit) within my Gameplay.ccb
(withing a physic node).
Then, I wanted to add that scenery from external file (because I would like to be able to switch between different scenery within the same scene). So I created a CCSprite
, I inserted my map inside and then my wall (this new file is map.ccbi
).
When I implement the map.ccbi inside my scene, the map is displayed, but the wall seems to be away (there is no collision between the character and the wall).
The map is implemented within the physic node of my Gameplay
scene.
Here's the part of the code where I am implementing the map:
- (void)didLoadFromCCB {
self.userInteractionEnabled = TRUE;
// Set the class as delegate for collision
_physicWorld.collisionDelegate = self;
_hero.physicsBody.collisionType = @"hero";
// Set up the map
CCNode *map = [CCBReader load:@"Map/TestIsland"];
// position the map
map.position = ccpAdd(_physicWorld.position, ccp(0.5, 0.5));
// add the map to the world
[_physicWorld addChild:map z:-2];
}
My map is implemented via a Class:
@implementation TestIsland
- (id)init {
self = [super init];
if (self) {
CCLOG(@"Map loaded");
}
return self;
}
@end