У меня есть массив, таймер, который добавляет новый объект в мой массив каждые 5 секунд, но у меня небольшая проблема.У меня есть код, который называется повторяющимся образом, который перемещает объекты в моем массиве, но по какой-то причине предыдущий объект, который появляется, перестает двигаться, когда новый объект появляется в моем массиве.Как сделать так, чтобы вызывался каждый отдельный объект в массиве, а не только тот, который создается последним?
Вот мой код, который вызывается для перемещения объектов:
for (UIView *astroids in astroidArray) {
int newX = astroids.center.x + 0;
int newY = astroids.center.y + 1;
astroids.center = CGPointMake(newX,newY);
}
Редактировать: Извините, вот мой код для моего массива:
// spawn the astroids every few seconds randomly along the x axis
// and remove them once they get off the screen
if ((gameStarted == YES) && (gameOver == NO)) {
int randomX = arc4random() % 320;
astroidArray = [[NSMutableArray alloc] init];
UIImage *astroid = [UIImage imageNamed:@"astroidwhite.png"];
UIImageView *astroids = [[UIImageView alloc] initWithImage:astroid];
//set X and Y of the new imageView
astroids.center = CGPointMake(randomX , -10);
//add to array
[astroidArray addObject:astroids];
//add to the view, so it gets displayed.
[self.view addSubview: astroids];
[astroids release];
}