I have a scene with buttons and node Level in which I load another scene (layer created with Sprite Builder):
-(void) didLoadFromCCB {
//the Gameplay Scene loaded
// tell this scene to accept touches
self.userInteractionEnabled = TRUE;
//load level in gameplay scene
CCScene *level = [CCBReader loadAsScene:@"Scenes/scene_01"];
[_levelNode addChild:level];
}
Everything is loading and I have a gameplay scene with common buttons and a scene_01
with sprites added as child.
Now I am trying to detect if a sprite from scene_01
was touched. I can track if touch occurred on _levelNode
:
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint _touchLocation = [touch locationInNode:_levelNode];
CCLOG(@"levelNode touched");
// Define which touched Object
if (CGRectContainsPoint([_part01 boundingBox], _touchLocation))
{
_part01.position = _touchLocation;
_touchingPart01 = YES;
_touchPoint = _touchLocation;
CCLOG(@"_part01 touched");
}
}
But the second part of code above is not working and console says the sprites were not found at all:
[1531:60b] CCBReader: Couldn't find member variable: _part01
My conclusion is - the parent scene has no access to sprites in loaded scene and the questions are:
Is it a good practice to have node where game switches child:levels instead of loading levels as scenes?
If Yes - how do I manage the objects inside that level, do I need more precise selector? (something like:
if (CGRectContainsPoint([***level.***_part01 boundingBox], _touchLocation)))
I think I could create
.ccb
files and create classes to describe these sprites in Cocos but it would be 5 sprites per level and dozens of levels which means I get 50+ classes which I believe isn't a good way to create a game. (I can't create a class for part and change its link to sprite due the lack of skill).