点击它时如何删除SCNNode?

问题描述 投票:1回答:1

我使用SceneView创建多维数据集,我想消除多维数据集动作的多维数据集。怎么能实现呢?

这是我创建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操作中删除Node。能帮帮我吗,并提出更好的建议,谢谢... :)

ios objective-c xcode scenekit scnnode
1个回答
1
投票

您需要使用[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];
}
© www.soinside.com 2019 - 2024. All rights reserved.