두 개의 정적 (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 - 아이폰
태그 메모 : 'spacemanager'태그가 있어야합니다. –