我有使用 SceneView 的 Creat Cubes,我想在点击操作时消失立方体。如何实现?
这是我创建 Cube 的代码
SCNBox *Box = [SCNBox boxWithWidth:2.0 height:2.0 length:2.0
chamferRadius:Radius];
Box.firstMaterial.diffuse.contents = [UIColor whiteColor];
SCNNode *cubeNode = [SCNNode nodeWithGeometry:Box];
[ArrBoxNode addObject:cubeNode];
self.sceneView.backgroundColor = [UIColor redColor];
self.view.backgroundColor = [UIColor grayColor];
cubeNode.position = SCNVector3Make(4,0,0);
[scene.rootNode addChildNode:cubeNode];
self.sceneView.scene = scene;
[self.sceneView sizeToFit];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.sceneView];
SCNHitTestResult *hitTestResult = [[self.sceneView
hitTest:touchPoint options:nil] firstObject];
SCNNode *hitNode = hitTestResult.node;
for (SCNNode *node in ArrBoxNode) {
[node removeFromParentNode];
}
}
但我无法从 Tap 操作中删除节点。能否请您帮助我,并提出更好的建议,谢谢...:)
最佳答案
您需要使用 [hitNode removeFromParentNode];
删除您正在触摸的节点
代码
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.sceneView];
SCNHitTestResult *hitTestResult = [[self.sceneView hitTest:touchPoint options:nil] firstObject];
SCNNode *hitNode = hitTestResult.node;
[hitNode removeFromParentNode];
}
关于ios - 如何在点击 SCNNode 时删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47977468/