# Keep running CGRectIntersect Method - Objective C

I have two UIImageViews. mainSprite, and enemy1. And I have a method that makes enemy1 start moving towards mainSprite. So here's that method.

-(void)enemy1Aggro{
if (CGRectIntersectsRect(mainSprite.frame, enemy1Aggro.frame)) {
if (mainSprite.center.x > enemy1.center.x) {
enemy1.center = CGPointMake(enemy1.center.x+2, enemy1.center.y);
}
if (mainSprite.center.x < enemy1.center.x) {
enemy1.center = CGPointMake(enemy1.center.x-2, enemy1.center.y);
}
if (mainSprite.center.y > enemy1.center.y) {
enemy1.center = CGPointMake(enemy1.center.x, enemy1.center.y+2);
}
if (mainSprite.center.y < enemy1.center.y) {
enemy1.center = CGPointMake(enemy1.center.x, enemy1.center.y-2);
}
}


} This works because I'm calling it on an IBAction that is a button that gets held down. But the problem is that when that button stops being pressed, this method stops running. So what I need is a way to have this method keep on running. Maybe a for loop? I'm not using anything like cocos2d, and I'm not using CoreGraphics. If you need to see any more of my code just ask.

Thanks :)

• it looks like he said he is not using cocos2d... – saiy2k Feb 18 '12 at 18:52

- (void)viewDidLoad

The above code will invoke the enemy1Aggro 30 times per second.