Quote:
Originally Posted by smasher
It makes everyone in the array "enemies" move by changing their center. Are you sure that your newEnemy is in "enemies?"
Post the code where you create (init/alloc) "enemies" , and where you add your newEnemy to "enemies" .
|
Code:
//Here is the spawnE...
-(void)spawnE {
UIImage *enemyImage = [UIImage imageNamed:@"enemy.png"];
UIImageView *newEnemy = [[UIImageView alloc] initWithImage: enemyImage];
int randomX = arc4random() % 320; // number from 0 to 319
newEnemy.center = CGPointMake( randomX, 0);
[enemies addObject:newEnemy];
[self addSubview: newEnemy];
}
/* and here is.. the complete move method with my enemy and my newEnemy
move code.
/*
-(void)move {
for (UIView *anEnemy in enemies){
float newX = anEnemy.center.x;
float newY = anEnemy.center.y + speedY;
anEnemy.center = CGPointMake(newX, newY);
}
CGPoint centerr = enemy.center;
centerr.y += speedY;
enemy.center = centerr;
if (centerr.y > 470){
[enemy removeFromSuperview];
}
if (CGRectIntersectsRect(enemy.frame, survivor.frame)) {
[survivor removeFromSuperview];
[self loose];
}
if (CGRectIntersectsRect(newEnemy.frame, survivor.frame)) {
[survivor removeFromSuperview];
[self loose];
}
}
The spawn code works perfectly...but the move