在我嘗試製作沒有物理引擎的遊戲時,我的iPod 4g真的很慢地運行代碼。代碼有效,但其速度非常慢。我想知道如果有人能幫助我讓它跑得更快。有人可以幫助我改進我的代碼,以便它可以更快地工作嗎?
-(void)Loop {
NSMutableArray *_remove = [NSMutableArray array];
for (UIImageView *b in _blocks) {
int i = 0;
for (UIImageView *b2 in _blocks) {
if (!CGRectContainsPoint(b2.frame, CGPointMake(b.center.x, b.center.y + b.frame.size.height/2)) && b != b2) {
i++;
}
}
if (i == [_blocks count] - 1 && b.image != wall) {
b.center = CGPointMake(b.center.x, b.center.y + 1);
} else if (b.image != wall) {
for (UIImageView *b2 in _blocks) {
for (UIImageView *b3 in _blocks) {
//Check for collitions
if (b !=b2 && ((CGRectContainsPoint(b2.frame, CGPointMake(b.center.x + b.frame.size.width/2, b.center.y)) && b.image == b2.image && b.image !=wall && b2.image != wall && CGRectContainsPoint(b3.frame, CGPointMake(b2.center.x, b2.center.y + b2.frame.size.height/2))) || (CGRectContainsPoint(b2.frame, CGPointMake(b.center.x, b.center.y + b.frame.size.height/2)) && b.image == b2.image && b.image !=wall && b2.image != wall))) {
[_remove addObject:b];
[_remove addObject:b2];
}
}}
}
}
for (UIImageView *b in _remove) {
[b removeFromSuperview];
[_blocks removeObject:b];
}
}
什麼代碼的作用是它消除了由側或上具有相同的圖像「塊」的頂部有一個「壁」或「塊」,並且也側的UIImageViews。換句話說刪除的圖像,如果他們是感人,具有相同的形象,如果他們仍然(低於塊)
你分析代碼? –
分析是做什麼的? – Jason
http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 –