Я использую Spacemanager с физикой бурундука для моей игры.
Я пытаюсь ударить по мячу в столб и заставить мяч исчезнуть. Я воссоздаю мяч в другом месте, чтобы пользователь мог попасть в другой столб. у меня есть форма шара и шар спрайт в качестве переменной члена.
Вот код для создания шара, колонн и т. Д.
ball = [smgr addCircleAt:cpv(1000,10) mass:0.5 radius:35];
ball->collision_type = kBallCollisionType;
ballSprite = [cpCCSprite spriteWithShape:ball file:@"head.png"];
//[ballSprite autoFreeShape];
[self addChild:ballSprite];
ballSprite.spaceManager = smgr;
//ballSprite.ignoreRotation = NO;
cpShape *dome = [smgr addRectAt:cpv(400,500) mass:1 width:400 height:100 rotation:0];
dome->collision_type = kRectCollisionType;
cpCCSprite *dome1 = [cpCCSprite spriteWithShape:dome file:@"001.png"];
[self addChild:dome1];
dome1.spaceManager = smgr;
cpShape *pillarone = [smgr addRectAt:cpv(300,300) mass:1 width:45 height:194 rotation:0];
pillarone->collision_type = kRectCollisionType;
cpCCSprite *pillar1 = [cpCCSprite spriteWithShape:pillarone file:@"004.png"];
[self addChild:pillar1];
pillar1.spaceManager = smgr;
cpShape *pillartwo = [smgr addRectAt:cpv(500,300) mass:1 width:45 height:194 rotation:0];
pillartwo->collision_type = kRectCollisionType;
cpCCSprite *pillar2 = [cpCCSprite spriteWithShape:pillartwo file:@"004.png"];
[self addChild:pillar2];
pillar2.spaceManager = smgr;
cpShape *staticground = [smgr addRectAt:cpv(510,25) mass:1 width:0 height:0 rotation:0];
cpCCSprite *staticground1 = [cpCCSprite spriteWithShape:staticground file:@"grass1-1024.png"];
[self addChild:staticground1 z:1 tag:0];
[smgr addCollisionCallbackBetweenType:kRectCollisionType
otherType:kBallCollisionType
target:self
selector:@selector(handleCollisionWithFragmentingRect:arbiter:space:)];
И ЗДЕСЬ КОД ДЛЯ ОБРАБОТКИ КОЛЛИЗИОНОВ.
- (void) handleCollisionWithFragmentingRect:(CollisionMoment)moment arbiter:(cpArbiter*)arb space:(cpSpace*)space{
if (moment == COLLISION_POSTSOLVE)
{
[self removeChild:ball->data cleanup:YES];
[smgr removeAndFreeShape:ball];
ball = [smgr addCircleAt:cpv(1000,10) mass:0.5 radius:35];
ball->collision_type = kBallCollisionType;
ballSprite = [cpCCSprite spriteWithShape:ball file:@"head.png"];
[self addChild:ballSprite];
ballSprite.spaceManager = smgr;
}
}
Когда первый шар попадает в столб, он прекрасно исчезает. но второй и несколько раз третий мяч, который я беру и ударю по столбу, разбивается с ошибкой следующим образом.
Chipmunk warning: Cannot remove a constraint that was not added to the space. (Removed twice maybe?)
Failed condition: cpArrayContains(space->constraints, constraint)
Я не уверен, где я ошибся, может кто-нибудь помочь, пожалуйста.
Спасибо.