Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

if (CGRectIntersectsRect(mainSprite.frame, enemy1Aggro.frame)) {
    if ( > { = CGPointMake(,;
    if ( < { = CGPointMake(,; 
    if ( > { = CGPointMake(,; 
    if ( < { = CGPointMake(,;

} 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 :)

share|improve this question
it looks like he said he is not using cocos2d... – saiy2k Feb 18 '12 at 18:52

You can use NSTimer to setup something like gameloop which calls ur method again and again

Your code should look somethings like this:

- (void)viewDidLoad
    [super viewDidLoad];
    [NSTimer scheduledTimerWithTimeInterval:1/30.0 target:self selector:@selector(enemy1Aggro) userInfo:nil repeats:YES];

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.