这是Scenekit代码,而不是sprite工具包。因此,我试图使用触摸开始方法中的盒子的名称访问它,在本例中是"盒子",但它超出了范围,我尝试使用与spritkit相同的技术,但它不一样。
//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{
}
}
在场景的rootNode
上调用-childNodeWithName:recursively:
。