基於Box2D的文檔和教程在網上查到(最好的一個在這裏http://www.iforce2d.net/b2dtut/collision-anatomy)我認爲碰撞事件處理beginContact應該每次碰撞僅出現一次。Box2D的碰撞beginContant occurrs不止一次
但我的經驗是,在某些情況下(我不能縮小這個下降到什麼特別的事至今)beginContact被調用一次以上。
具體例子:
1st fixture is a box, belongs to static body and is a sensor
2nd fixture (which is also player body in 2d game I'm building)
is a polygon, belongs to dynamic body and is not a sensor.
Both are large enough so in debug mode it is absolutely clear
when these fixtures start to overlap and when they part.
Result is - while player body fixture passes through static sensor,
beginContact is called 3-4 times or more while fixtures keep oveplapping.
Velocity is moderate (fixtures keep overlapping for a whole second and more).
我懷念在文檔中的東西嗎?有沒有辦法解決這個問題?
是的,這兩個是唯一在場的燈具 - 他們是球員和獎金掛在空中。我發現,這個問題涉及到fixtureShape - 我用ChainShape得到鬼頂點advantge(順便說一句感謝這些偉大的教程),這似乎可每每個鏈節beginContact。我已經將簡單的PolygonShape夾具添加到玩家身上,並且需要使用斧子 - 每次碰撞開始接觸呼叫。 – Lez77 2014-09-06 13:16:58