0

詳細に説明させてください。if(CGRectContainsPoint([hole1 boundingBox], ball1.position))条件が満たされるたびに、予定外、セレクター、アニメーションを呼び出すボール体の破壊など、多くのことを行います (以下のコードを参照してください)。ほとんどの場合、これは適切に機能します。しかし、ボールが本当に穴に近づいたとき (穴に触れたが、上記の条件を真にするのに十分ではない)、または非常に速い速度で穴に向かって投げられた場合、アプリケーションが終了することがあります。このセクションで実行された多くのアクションをコメントして確認しましたが、何の役にも立たず、アプリケーションを終了させるために何らかの努力が行われたときにアプリケーションが終了し続けます。

if(CGRectContainsPoint([hole1 boundingBox], ball1.position))
{
    ballBody->SetLinearVelocity(b2Vec2(0.0f,0.0f));
    ballBody->SetAngularVelocity(0.0f);

    [self unschedule:@selector(tick:)];
    self.isTouchEnabled = NO;

    [self removeChild:ball1 cleanup:YES];
    world->DestroyBody(ballBody);

    // create the sprite sheet
    CCSpriteSheet *spriteSheet;

    GolfBallsAppDelegate *appDelegate = (GolfBallsAppDelegate *)[[UIApplication sharedApplication] delegate];
    if([appDelegate.ballValue isEqualToString:@"cricketball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"cricket_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"ironball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"iron_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"golfball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"golf_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"soccerball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"soccer_ball_strip.png"];
    }
    else if([appDelegate.ballValue isEqualToString:@"basketball"])
    {
        spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"basket_ball_strip.png"];
    }

    spriteSheet.position = ccp(hole1.position.x,60);
    [self addChild:spriteSheet];

    float frameWidth = 96;
    float frameHeight = 84;

    CCSprite *sprite = [CCSprite spriteWithTexture:spriteSheet.texture rect:CGRectMake(0, 0, frameWidth, frameHeight)];

    [spriteSheet addChild:sprite];

    //if(animation)
    {
        // create the animation
        CCAnimation *spriteAnimation = [CCAnimation animationWithName:@"potting" delay:0.1f];

        int frameCount = 0;
        for (int x = 0; x < 6; x++) 
        {
            // create an animation frame
            CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:spriteSheet.texture rect:CGRectMake(x*frameWidth,0*frameHeight,frameWidth,frameHeight) offset:ccp(0,0)];
            [spriteAnimation addFrame:frame];

            frameCount++;

            // stop looping after we've added 14 frames
            if (frameCount == 6)
            {
                //[self removeChild:spriteSheet cleanup:YES];
                break;
            }
        }

        // create the action
        CCAnimate *spriteAction = [CCAnimate actionWithAnimation:spriteAnimation];
        //CCRepeatForever *repeat = [CCRepeatForever actionWithAction:spriteAction];

        // run the action
        [sprite runAction:spriteAction];
        //[sprite runAction:repeat];
    }
    [self schedule:@selector(loading) interval:0.5];
    [self schedule:@selector(holeFinish) interval:1];
    //[self removeChild:spriteSheet cleanup:YES];
}

どんな提案でも大歓迎です。

編集:私が見つけたのは、次の行の問題です[self removeChild:ball1 cleanup:YES]; world->DestroyBody(ballBody); (可能性があります)。しかし、常に発生するわけではないので(前述のとおり)、ばかげています。

4

1 に答える 1

2

あなたの問題は、b2Worldが「ロック」されているときにボディを削除しようとしていることにあると思います(世界が衝突の解決に忙しいとき)。

オブジェクトに削除の準備ができているというフラグを立て、次のループの開始時に削除してみてください。

交換:

[self removeChild:ball1 cleanup:YES];
world->DestroyBody(ballBody);

ball1.isDead = YES;

そして、次のゲーム ループの開始時に:

for (Ball b in balls)
{
    if (b.isDead)
        world->DestroyBody(b.ballBody);
}
于 2011-08-31T07:31:03.490 に答える