gpt4 book ai didi

ios - 如何在点击 SCNNode 时删除它?

转载 作者:行者123 更新时间:2023-11-29 11:38:19 26 4
gpt4 key购买 nike

我有使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com