在我尝试在没有物理引擎的情况下制作游戏时,我的 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];
}
}
代码的作用是删除具有“墙”或“块”并且并排或位于具有相同图像的“块”顶部的 UIImageView。换句话说,如果它们正在触摸,则删除具有相同图像的图像,并且如果它们是静止的(下面有一个块)