更改CCSprite的physicsBody类型CCPhysicsBodyTypeStatic崩溃应用程序

时间:2014-12-31 09:03:56

标签: ios cocos2d-x game-physics cocos2d-x-3.0 chipmunk

我有一个包含多个 CCSprite 的CCSprite,因为它是孩子。所有儿童精灵的物理体都属于 CCPhysicsBodyTypeDynamic 类型。我需要在按下按钮后立即停止父CCSprite。因此,我将其中的每一个都设置为 CCPhysicsBodyTypeStatic 类型,并再次将其类型转换为 CCPhysicsBodyTypeDynamic 。但有时它会崩溃应用程序。调试器在静态void显示崩溃 Chipmunk物理库中的 cpBBTree.c 的PairsClear(Node * leaf,cpBBTree * tree)功能。

enter image description here

和函数,我用来立即停止容器精灵

-(void)stop{

    bodySprite.physicsBody.type = CCPhysicsBodyTypeStatic;
    collideSprite.physicsBody.type = CCPhysicsBodyTypeStatic;
    leftWheel.physicsBody.type = CCPhysicsBodyTypeStatic;
    rightwheel.physicsBody.type = CCPhysicsBodyTypeStatic;
}

-(void)startMoving{

    bodySprite.physicsBody.type = CCPhysicsBodyTypeDynamic;
    collideSprite.physicsBody.type = CCPhysicsBodyTypeDynamic;
    leftWheel.physicsBody.type = CCPhysicsBodyTypeDynamic;
    rightwheel.physicsBody.type = CCPhysicsBodyTypeDynamic;
}

-(void)moveToLeft{

    // Player's moving direction is going to be changed, going to apply break by stopping the whole body, and then allowing it to move
    if ((currentMovingDirection != MovingDirectionLeft)) {
        currentMovingDirection = MovingDirectionLeft;
        [self applyBreak];
    }

    [leftWheel.physicsBody applyTorque:WheelTorque];
    [rightwheel.physicsBody applyTorque:WheelTorque];
}
-(void)moveToRight{

    // Player's moving direction is going to be changed, going to apply break by stopping the whole body, and then allowing it to move
    if ((currentMovingDirection != MovingDirectionRight)) {
        currentMovingDirection = MovingDirectionRight;
        [self applyBreak];
    }
    [leftWheel.physicsBody applyTorque:-WheelTorque];
    [rightwheel.physicsBody applyTorque:-WheelTorque];

}

-(void)applyBreak{
    [self stop];
    [self startMoving];
}

在按钮点击事件中,我将 movetoLeft()调用为 moveToRight()。这些调用不是来自碰撞委托。有没有办法立即停止容器精灵的子项或避免崩溃?

0 个答案:

没有答案