我有兩個靜態(STATIC_MASS)SpaceManager精靈。一個是另一個的孩子 - 我的意思是一種構建另一個孩子,但儘管孩子的圖像出現在正確的位置,但這個孩子似乎並不存在於花栗鼠的物理引擎中,就像我會期待。在我的情況下,我有一個背板(矩形精靈)和一個箍(一個圓形精靈)。因爲我可能想移動籃板,所以我想把籃筐安裝在籃板上,這樣籃筐就可以隨籃板一起自動移動。如何在使用SpaceManager時使靜態精靈成爲cocos2D中另一個精靈的子節點
在這裏,我們看到一個帶有連接箍的旋轉籃板。它在屏幕上看起來沒問題,但其他物體只能從籃板上彈開,但是通過籃筐(在這個術語的不好意義上)。我的孩子精靈似乎並不存在於物理引擎中?
// Add Backboard
cpShape *shapeRect = [smgr addRectAt:cpvWinCenter mass:STATIC_MASS width:200 height:10 rotation:0.0f ];// We're upgrading this
cpCCSprite * cccrsRect = [cpCCSprite spriteWithShape:shapeRect file:@"rect_200x10.png"];
[self addChild:cccrsRect];
// Spin the static backboard: http://stackoverflow.com/questions/2691589/how-do-you-make-a-sprite-rotate-in-cocos2d-while-using-spacemanager
// Make static object update moves in chipmunk
// Since Backboard is static, and since we're going to move it, it needs to know about spacemanager so its position gets updated inside chipmunk.
// Setting this would make the smgr recalculate all static shapes positions every step
// cccrsRect.integrationDt = smgr.constantDt;
// cccrsRect.spaceManager = smgr;
// Alternative method: smgr.rehashStaticEveryStep = YES;
smgr.rehashStaticEveryStep = YES;
// Spin the backboard
[cccrsRect runAction:[CCRepeatForever actionWithAction:
[CCSequence actions:
[CCRotateTo actionWithDuration:2 angle:180],
[CCRotateTo actionWithDuration:2 angle:360],
nil]
]];
// Add the hoop
cpShape *shapeHoop = [smgr addCircleAt:ccp(100,-45) mass:STATIC_MASS radius: 50 ];
cpCCSprite * cccrsHoop = [cpCCSprite spriteWithShape:shapeHoop file:@"hoop_100x100.png"];
[cccrsRect addChild:cccrsHoop];
上面的代碼是有點重擊。箍的圖像顯示在接下來的板上,這是我想要的,如果我檢測到碰撞,碰撞只發生在屏幕的左下角。奇怪的是,即使我正在檢測到一個碰撞,我的物體實際上並不會相互碰撞,它只是通過它而不是反彈。
注:SpaceManager是與cocos2D上,iphone
標記說明:這應該有一個'spacemanager'標記 – 2010-04-22 15:49:47