gpt4 book ai didi

ios - 如何检测物理 body 区域的触摸?

转载 作者:行者123 更新时间:2023-11-29 03:00:30 25 4
gpt4 key购买 nike

我确实使用此代码创建了 SKSpriteNode,并且物理主体是圆形。我如何检查用户是否触摸了物理主体中的耳朵?

self = [super initWithColor:[SKColor clearColor] size:CGSizeMake(200, 200)];
//...
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.size.width/2.0f];
self.userInteractionEnabled = YES;

最佳答案

我确实使用这段代码找到了解决问题的方法:

CGMutablePathRef pathRef;
// Fill pathRef with points and create phisycs body using pathRef.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self.scene];

if (CGPathContainsPoint(pathRef, nil, touchLocation, NO)) {
// If we are here it means user did touche physic body.
}
}

关于ios - 如何检测物理 body 区域的触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23362072/

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