为什么sprite套件没有检测到我的第二个“碰撞”
- 假设我已正确设置所有物理主体和动态属性,
- 我有一个玩家和一堵墙
- 当我向右滑动时,用户撞到墙壁并停止,Xcode 会检测到该碰撞。
- 我面临的问题是,由于用户现在靠在墙上,当我再次向右滑动时,它不会检测到碰撞,但您仍然可以看到玩家试图向右碰撞它。这就是为什么我引用碰撞,因为从技术上讲它不是碰撞,但它应该是因为用户试图向右移动
我的问题是精灵套件不支持的吗?
- Assume I have all my physics body and dynamic properties set properly
- I have a player and a wall
- When I swipe right, the user hits the wall, and stops, and Xcode detects that collision.
- The problem im facing is that since the user is now against the wall, when I swipe right again, it doesn't detect the collision but you can still see the player trying to goto the right bumping it. This why I quoted collision since it technically is not a collision but it should be since the user is trying to move to the right
Is my issue something not supported by sprite kit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑这是因为
didBegin(contact:)
在撞墙时被解雇,但您仍在撞墙,因此DIDEND(contact:)
尚未发射,所以您无法启动新的联系人。请记住,这不是碰撞,而是联系 - 碰撞是一个对象弹出另一个对象并由SK游戏引擎处理的;联系人是一个对象触摸另一个对象并通过用户代码处理的。
您是否在用户和墙之间启用了碰撞?如果没有,则两个精灵可以重叠,并且联系将不会结束。您可能必须设置碰撞并让用户稍微从墙壁上弹起,从而结束了联系,并可以检测到另一个联系人。
另外,您可以在
didBegin(contact:)
中设置标志(接触尚未结束)。I suspect it's because
didBegin(contact:)
fired when you hit the wall but you are still hitting the wall, thereforedidEnd(contact:)
hasn't fired and so you can't start a new contact.Remember it's not a collision but a contact - collisions are when one object bounces off another and are handled by the SK game engine; contacts are when one object touches another and are handled by user code.
Do you have collisions enabled between the user and the wall? If not, the 2 sprites can overlap and the contact won't end. You might have to set up collisions and have the user bounce off the wall slightly, thus ending the contact and enabling another contact to be detected.
Alternatively you can set a flag in
didBegin(contact:)
which you clear indidEnd(contact:)
and take some action every time the user swipes and the flag is still set (the contact hasn't ended).