How do I retrieve a node in Xcode Scenekit if it's out of scope?

254 Views Asked by At

Here is the Scenekit code instead of sprite kit. So i'm trying to access the box within the touches began method using it's name which in this case is "box" but it's out of scope and I try'd using the same technique like spritekit but it's not the same.

   //BOX
    SCNBox *boxGeometry = [SCNBox boxWithWidth:10
                                        height:10
                                        length:10
                                 chamferRadius:0.3];
    SCNNode *box = [SCNNode nodeWithGeometry:boxGeometry];
    box.position = SCNVector3Make(0, 10, 0);
    boxGeometry.firstMaterial.diffuse.contents = [UIImage imageNamed:@"wood.png"];
    boxGeometry.firstMaterial.specular.contents = [UIColor whiteColor];
    boxGeometry.firstMaterial.shininess = 10.0;
    box.name = @"box";
    [scene.rootNode addChildNode:box];




-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];


    if (location.x > 160) {
    }
    else{
    }



}
1

There are 1 best solutions below

9
mnuages On

call -childNodeWithName:recursively: on the scene's rootNode.