これはおそらく、割り当てようとしているオブジェクトの大きさによって決まりますが、私がこのようなやり方をしているかどうかを知りたければ、後で問題に遭遇します。今はすべてがうまく見えます。私はCocos2Dを使用しています。私は割り当てとforループ内のすべてのforループcheckDistanceの割り当てを解除していますかObjective Cでの割り当てと割り当て解除の速さはどれくらいですか?
-(void) checkCGPointDistances{
CCSprite *tempSp;
CCLabelTTF *tempLabel;
for(int i=0; i<hummingBirdsMax; ++i){
tempSp = [hummingBirds objectAtIndex:i];
checkDistance = [[CheckDistance alloc] init];
if([checkDistance checkDistanceWithLimit:tempSp.position withPoint2:hero.heroSprite.position withLimit:150] == YES){
if(hero.heroSprite.position.x > tempSp.position.x){
tempSp.flipX = YES;
}else{
tempSp.flipX = NO;
}
tempLabel = [hummingLabels.labelsArr objectAtIndex:i];
[tempLabel setString:@"Hello!"];
[hummingLabels.deactivateLabelToggle replaceObjectAtIndex:i withObject:[NSNumber numberWithInt:1]];
}
[checkDistance release];
}
if(abilityRushH == 0){
checkDistance = [[CheckDistance alloc] init];
if([checkDistance checkDistanceWithLimit:rushH.rushHSprite.position withPoint2:hero.heroSprite.position withLimit:32] == YES){
[rushH.rushHSprite removeFromParentAndCleanup:NO];
abilityRushH = 1;
NSLog(@"horizontal rush activated");
}
[checkDistance release];
}
if(abilityRushV == 0){
checkDistance = [[CheckDistance alloc] init];
if([checkDistance checkDistanceWithLimit:rushV.rushVSprite.position withPoint2:hero.heroSprite.position withLimit:32] == YES){
[rushV.rushVSprite removeFromParentAndCleanup:NO];
abilityRushV = 1;
NSLog(@"vertical rush activated");
}
[checkDistance release];
}
}
お知らせ:
は、例えば、この方法を取りますか?このメソッドは非常に迅速にタイマーで呼び出されています。私がループの中に何度も何度も割り当てをすることを決めたのは、hummingBirdsMaxの数が0になる可能性があるからです。割り当てを一切する必要がないからです。私はちょうどhummingBirdsMax> 0かどうかを調べることができると思うが、それは私がそれを行う方法が大きな違いを生むのだろうか?
割り当てるクラスは、CGPointとの間の距離をチェックしてboolを返します。
あなたは 'CheckDistance'の実装を投稿できますか?特に 'init'メソッドは? – Yuji