Domanda

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
È stato utile?

Soluzione

The keyword for this trouble should probably be sub-folder (or "tree").

Sprite builder is actually not supporting joint (sub-folder to a CCNode) while importing a node.

So one of the solution while facing such problem is to change the way you made your CCNode.

In this case, it have been solved by changing this:

(LAYER1 >>> LAYER2 >>> LAYER3 >>> ........)

CCNode >>> CCSprite + CCPhysicNode >>> CCNode(Wall) + CCNode(Obstacle) + ....

To this:

CCNode >>> CCSprite + CCNode(wall) + CCNode(Obstacle) + ....

Thanks to @Tibor for warning me that the implementation was good (it induced me that the trouble should be in the interface of SB) and for giving me the good tips for debugging my work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top