I have an app that randomly creates a UIImageView (enemy) at one of three "spawn points." To move them towards their destination (a player on the screen), I used CoreAnimation with things such [UIView beginAnimation...]. Now, though, I've begun to need to implement collision detection. Unfortunately, there is no way to do this between the animated enemy and the player using something like CGRectIntersectsRect(). To solve this, I merely decided to animate this using an NSTimer (calling a function every .01 seconds moving the image forward). Strangely, the image never moves, and the enemy images just pile on top of each other. I've tried numerous methods, but here's the most basic one (which also doesn't work):
I have an NSTimer in the viewDidLoad method, too:
Any ideas as to what is causing the problem?
Code:
-(void)animateEnemy{
CGPoint eCenter = enemy.center;
enemy.center = CGPointMake(eCenter.x, eCenter.y++);
}
I have an NSTimer in the viewDidLoad method, too:
Code:
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(animateEnemy) userInfo:nil repeats:YES];
Any ideas as to what is causing the problem?