Why does collision work properly for convex polygon based physicsBody but touchesMoved doesn't

青春壹個敷衍的年華 提交于 2019-12-08 09:33:21

问题


I setup an SKSprite (s1) to have physicsBody with polygon from path:

s1.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];

and the other one (s2) has physicsBody generated from its surrounding rectangle:

s2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:e.size];

and the collisions of the two sprites are fine, they only happen when the actual pixels from the s1's polygon path and surrounding rectangle from the s2 collide (and not the surrounding rectangles from each of the sprites). This is fine. But the touchesMoved in the s1 - which has polygon based body - occurs when its surrounding rectangle is touched - even though it has the polygon based physicsBody (see above code for setting the physicsBody of s1). How can I solve this problem and have this event only fire when it should, which is when actual pixels (defined by the polygon based physicsBody) are touched?

I tried detecting the body at point:

SKPhysicsBody * draggedOverBody = [self.physicsWorld bodyAtPoint:location];

draggedOverNode = draggedOverBody.node;

and also it only detects the bounding rectangle instead of the polkygon physicsBody. Very frustrating.

来源:https://stackoverflow.com/questions/35692087/why-does-collision-work-properly-for-convex-polygon-based-physicsbody-but-touche

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!