嗨我想在我的游戏上有一个选择框。 我认为使用'SpriteKit'叠加制作是最简单的方法 但有没有任何API可以检测'SKShapeNode'的交集 和'SCNNode'(忽略Z轴的路径)?
我尝试做了什么:
_unitsArray
是一个SCNNodes
数组,我希望它们在SKScene
for (SCNNode * node in _unitsArray)
{
SCNVector3 min = SCNVector3Zero;
SCNVector3 max = SCNVector3Zero;
[node getBoundingBoxMin:&min max:&max];
NSLog(@"Min Before %lf, %lf, %lf", min.x, min.y, min.z);
NSLog(@"Max Before %lf, %lf, %lf", max.x, max.y, max.z);
min = vector3Multiply(min, node.scale);
max = vector3Multiply(max, node.scale);
//Lets Get Nodes's Position
SCNVector3 position = node.position;
NSLog(@"Position = %lf, %lf, %lf", position.x, position.y, position.z);
SCNView * view = (SCNView *)self.view;
SCNVector3 posinView = [view projectPoint:position];
NSLog(@"Position in View = %lf, %lf, %lf", posinView.x, posinView.y, posinView.z);
min = [view projectPoint:min];
max = [view projectPoint:max];
NSLog(@"Min Scaled + Projected %lf, %lf, %lf", min.x, min.y, min.z);
NSLog(@"Max Scaled + Projected %lf, %lf, %lf", max.x, max.y, max.z);
CGFloat width = max.x - min.x;
CGFloat height = max.y - min.y;
CGRect maybeRect = CGRectMake(posinView.x - width /2, posinView.y - height /2, width, height);
SKSpriteNode * Snode = [SKSpriteNode spriteNodeWithColor:[SKColor yellowColor] size:maybeRect.size];
[Snode setPosition:CGPointMake(posinView.x, posinView.y)];
[self addChild:Snode];
}
由于某些原因,Snode比预期的大两倍:-O 我也不知道如何处理返回的Z. 某些人可以解释一下吗?