0
我想使用ios的scenekit制作游戏。我从SceneKit模板开始,Xcode给了我们(一个旋转的飞机)。已经提供了用于识别用户是否在屏幕上轻敲的handleTap方法。我想制作一个SCNBox并识别用户是否点击它,但我很困惑handleTap是如何工作的。 是否必须在handleTap中添加框几何? 有人可以告诉我如何将一个盒子放在屏幕的中心,以便识别它是否被点击。重新确认SceneKit中的对象是否已被点击
这里是handleTap代码:
- (void) handleTap:(UIGestureRecognizer*)gestureRecognize{
// retrieve the SCNView
SCNView *scnView = (SCNView *)self.view;
// check what nodes are tapped
CGPoint p = [gestureRecognize locationInView:scnView];
NSArray *hitResults = [scnView hitTest:p options:nil];
// check that we clicked on at least one object
if([hitResults count] > 0){
// retrieved the first clicked object
SCNHitTestResult *result = [hitResults objectAtIndex:0];
// get its material
SCNMaterial *material = result.node.geometry.firstMaterial;
// highlight it
//[SCNTransaction begin];
//[SCNTransaction setAnimationDuration:0.5];
// on completion - unhighlight
[SCNTransaction setCompletionBlock:^{
[SCNTransaction begin];
[SCNTransaction setAnimationDuration:0.5];
material.emission.contents = [UIColor blackColor];
[SCNTransaction commit];
}];
material.emission.contents = [UIColor redColor];
[SCNTransaction commit];
}
}
是什么result.node? –
好吧,在模板中你有'SCNHitTestResult * result = [hitResults objectAtIndex:0];''和'node'只是'SCNHitTestResult'的一个属性' – mnuages
所以我需要调用一个新的句柄方法,方法内部的if语句 –