Quote:
Originally Posted by smasher
Here's code to do something similar - it will put 10 copies of the same image on the screen, and put them in an array so you can get to them later. This code would work in viewDidLoad of a viewController, for example.
Code:
//declare the array in the .h file if you want to accessible
//from all methods.
NSMutableArray *arrayOfBalls
//create the array
arrayOfBalls = [[NSMutableArray alloc] init];
UIImage *ballImage = [UIImage imageNamed:@"ball.png"];
for (int i=0; i<10 ; i++){
UIImageView *newBall = [[UIImageView alloc] initWithImage: ballImage];
//set X and Y of the new imageView
newBall.center = CGPointMake(100 + i*10, 100+ i*10);
//add to array
[arrayOfBalls addObject:newBall];
//add to the view, so it gets displayed.
[self.view addSubview: newBall];
}
Not sure why - the syntax is fine. You might get a warning if you already have a variable called myBlock; when you make two variables with the same name in different scopes, the local one hides the gobal one.
|
,But if i already have a array of enemies do i need another one?
My array of enemies contains uiimageview of a enemy that i added to the array when the game starts and i have a timer to move the enemy, a timer to call spawnenemy method and a timer to keep score...
And i need to spawn enemies randomly in the x axe (i only need one type of enemy that i have added to the array)... how can this be done??
And how can i increase a timers intervals in a void?? that is being called some time.....
Thanks for all current replies and future...
