2つの静的(STATIC_MASS)SpaceManagerスプライトがあります。一方はもう一方の子です。つまり、一方の種類がもう一方の種類を構築しますが、子の画像は適切な場所に表示されますが、子は私のようにシマリス物理エンジンに存在していないようです。期待するだろう。私の場合、バックボード(長方形のスプライト)とフープ(円形のスプライト)があります。バックボードを動かしたいので、フープをバックボードに取り付けて、フープがバックボードと一緒に自動的に動くようにします。
ここでは、フープが取り付けられた回転するバックボードが表示されます。画面上では問題ないように見えますが、他のオブジェクトはバックボードで跳ね返るだけで、フープを通り抜けます(悪い意味で)。私の子供のスプライトは物理エンジンに何が存在しないようですか?
// 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を操作するためのツールキットです。