Shaun
Shaun

Reputation: 1

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

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{
    }



}

Upvotes: 0

Views: 259

Answers (1)

mnuages
mnuages

Reputation: 13462

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

Upvotes: 2

Related Questions