1

私は Cocos2D で約 3 年間、透明な背景を使用して UIView を表示するゲームを開発してきました。これは、Cocos2D がシーンの遷移を行う際に視差の背景を引き続き実行するためです。

iOS 7 にアップデートしたときに始まった新しい問題が発生しています。速度低下は、次の状況が組み合わさって発生します。

-視差背景のフレーム位置が変更された場合のみ。

-小さなスプライトとパーティクル効果を放出する敵を破壊した場合。

つまり、これはこれら 2 つの組み合わせであり、たまにしか発生しません。スローダウンが発生しても、フレーム レートのデバッグ値は低下しません。新しいシーンをロードすると、通常に戻ります。別の敵を倒すとスローダウンも消えることがあります。

ゲーム内のほぼすべてのフレームで実行される視差 UIView のコードがあります。この問題を 1 行にまとめました。

-(void)updateImagePosWithPos:(CGPoint)pos{ // in game

    // create vel based on last currentPos minus new pos

    CGPoint vel = CGPointMake(currentPos.x-pos.x, currentPos.y-pos.y);

    // init variables tmpVel and tempTotalImages

    CGPoint tmpVel = CGPointZero;

    int tmpTotalImages = 0;

    // create indexLayerArr

    NSMutableArray *indexLayerArr = [NSMutableArray array];

    // for every parallax layer, add the number of images horizontally minus 1 to indexLayerArr

    for (int j=0; j<totalLayers; ++j){

        [indexLayerArr addObject:[NSNumber numberWithInt:[[totalImagesArr objectAtIndex:j] intValue]-1]];

    }

    int i = 0;


    for (UIImageView *imageView in self.subviews) {

        CGRect tmpRect = CGRectZero;

        NSMutableArray *tmpRectArr = [rectContainer objectAtIndex:imageView.tag];

        float speed = 0.00;


        tmpTotalImages = [[totalImagesArr objectAtIndex:imageView.tag] intValue];

        speed = [[speedArr objectAtIndex:imageView.tag] floatValue];

        tmpVel = CGPointMake(vel.x*speed, vel.y*speed);

        i = [[indexLayerArr objectAtIndex:imageView.tag] intValue];

        tmpRect = [[tmpRectArr objectAtIndex:i] CGRectValue];


        if(tmpRect.origin.x - tmpVel.x > wins.width){

            tmpRect.origin.x -= (tmpTotalImages)*tmpRect.size.width;

        }
        else if(tmpRect.origin.x - tmpVel.x < -tmpRect.size.width){

            tmpRect.origin.x += (tmpTotalImages)*tmpRect.size.width;

        }

        tmpRect.origin.x -= tmpVel.x;
        tmpRect.origin.y += tmpVel.y;

        [tmpRectArr replaceObjectAtIndex:i withObject:[NSValue valueWithCGRect:tmpRect]];


        imageView.frame = [[tmpRectArr objectAtIndex:i] CGRectValue]; // <-- slow down cause



        i--;

        [indexLayerArr replaceObjectAtIndex:imageView.tag withObject:[NSNumber numberWithInt:i]];


    }

    currentPos = CGPointMake(pos.x, pos.y);

}

コメント行 imageView.frame = [[tmpRectArr objectAtIndex:i] CGRectValue]; を参照してください。

したがって、その行をコメントアウトしても、問題は発生しません。行を維持し、tempRect の値を変更しない場合、問題も発生しません。

UIImageView のフレーム位置を変更する際に iOS 7 に問題があるようですが、たまにしかありません。他にどのような代替手段を使用できるか疑問に思っていますか? それとも、iOS 7 で何か間違ったことをしているのでしょうか?

4

1 に答える 1