Search code examples
addchildcocos3d

add image as child of a CC3Node


I'm using Cocos3D. There i've a list of different CC3Nodes. I want to put an image next to each of it. My problem is: how to create a new CC3Node and add it as a Child.


Solution

  • You need to doing something like this:

    CC3PlaneNode *imageNode = [CC3PlaneNode nodeWithName:@"One Plane Node on 3D Object"];
    [imageNode populateAsCenteredRectangleWithSize: CGSizeMake(200.0, 200.0)
        andTessellation:ccg(40, 40) withTexture: [CC3Texture textureFromFile:@"Your Image Address"] invertTexture: YES];
    imageNode.material.specularColor = kCCC4FLightGray;
    imageNode.shouldCullBackFaces = NO;
    [imageNode retainVertexLocations];
    [self addChild:imageNode];
    

    And for doing this for each Node:

    CC3PlaneNode *newImageNode = [imageNode copyWithName:@"New Node Name"];
    ...
    [self addChild:newImageNode];
    

    At the end of it, if you want to add these node each node as a child do:

    [previousNode addChild:newNode];  
    

    instead of:

    [self addChild:newNode];
    

    I hope it works for you!