tags:

views:

31

answers:

1

I'm trying to make it so when my imageviews are spawned to the screen they scroll downwards but for some reason all my astroids do is spawn in place and don't move... here's my code.

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(100 , 100 );

astroids.center = CGPointMake(astroids.center.x - astroidVelocity.x ,    astroids.center.y - astroidVelocity.y);

astroidVelocity = CGPointMake(0,5);


 //add to array
 [astroidArray addObject:astroids];

 //add to the view, so it gets displayed.


 [self.view addSubview: astroids];
A: 

I am not quite sure why they would move - if astroid velocity is fixed, this code will always put an asteroid at 100,100 offset by whatever the velocity value is...

is this code called repeatedly?

If so I'd only ever add the objects to the view once, and then just modify the astroids.center every time you want to move it.

Really though you should probably use CoreAnimation for this, or more likely some kind of 2D graphics engine using OpenGL like Cocos2D.

Kendall Helmstetter Gelner
Is there a way to use a for loop in a seperate method that will tell each object in my array to move ?