Search code examples
cocos2d-iphone

CClightNode cocos2d - No light Collection Error


I am doing a very basic thing of adding a lightNode to the Scene.

    CCLightNode *light1 = [CCLightNode lightWithType:CCLightPoint
                                 groups:nil
                                  color:[CCColor colorWithRed:1.0f      green:0.5f blue:0.2f]
                              intensity:10.0f];

       light1.position = CGPointMake(winSize.width/4, winSize.height/4);

       [self addChild:light1];

But I keep getting this error

2015-11-08 20:29:41.383 Effects[7441:117051] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The light node is in a scene but there's no light collection.'

I have tried everything and I still seem to get this error. I have alos looked online for a resolution and I am not finding and answers and I am not sure how to get around it.

There is just one tutorial and that also shows how to do it in spriteBuilder and not in code.

Is there a way to add the light in the light Collection at all? Thanks


Solution

  • Ensure that the CCLightNode is being added to a CCScene, and not just a CCNode. CCScenes contain CCLightCollections, which CCLightNodes require.