2010-04-22 35 views
1

我有兩個靜態(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

+0

標記說明:這應該有一個'spacemanager'標記 – 2010-04-22 15:49:47

回答

1

工作的工具包簡單的答案是,它是不是真的有可能。花栗鼠喜歡在世界座標中的一切,當你開始在cocos2d中創建親子關係時,你正在設置座標系統的錯誤匹配...

但是......我的確嘗試在沒有太多成功的情況下解決這個問題問題是旋轉,我相信)看看SpaceManager.m中的函數「eachShapeAsChildren」。如果你設置SpaceManager的iterateFunc屬性指向這個函數,你可以看到會發生什麼......

在某些時候,我可能會再給它一次;事實上我已經感受到了更多的啓發。

2

問題是,父母的子女關係在物理引擎中沒有意義。您可以將多個形狀附加到同一個物體,以便在移動一個物體時移動多個形狀。

相關問題