基于cocos2d-js和chipmunk,創(chuàng)建了一個簡單Scene和一個layer洞翩,初始化space稽犁,加入一個body、一個shape骚亿、一個physicsSprite已亥,然后支持拖拽layer和body。
遇到第一個坑來自于cocos2d-js来屠,它有幾種渲染模式虑椎,定義在project.json里,默認為0
// "renderMode" sets the renderer type, only useful on web :
// 0 - Automatically chosen by engine
// 1 - Forced to use canvas renderer
// 2 - Forced to use WebGL renderer, but this will be ignored on mobile browsers
其中canvs渲染模式下俱笛,physicsSprite::syncPhycisTransform()函數(shù)坐標位置轉換有bug捆姜,導致屏幕上顯示的圖像和物理節(jié)點位置不一致。此問題已經修復如下
第二個坑來自于chipmunk迎膜,問題出在pointQueryFirst泥技,這個函數(shù)是用來查詢觸摸點位置是否存在物理節(jié)點。這個bug導致我們在模擬器磕仅、web上都運行正常珊豹,但是在device上出錯。目前暫時的解決辦法是把第二個參數(shù)改為cp.ALL_LAYERS榕订,如下
var shape = _space.pointQueryFirst(_mousePos, cp.ALL_LAYERS, cp.NO_GROUP)