Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-26-2009, 04:24 PM   #9 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Thumbs up

Quote:
Originally Posted by LeopardDevX View Post
What if i had a game where i wanted to pop up enemies from a array called "enemies" and the image is named "enemy", if i wanted them to pop up randomly on the "x" axe with the width of the view.
How should i set that up?

That would really help me understanding NSMutableArrays
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];
	}

Quote:
The for (UIView *myBlock in safeKeeping).....
method isnt working...
im getting a warning on myBlock.....
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.
__________________

Free Games!
smasher is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,847
Threads: 89,213
Posts: 380,661
Top Poster: BrianSlick (7,129)
Welcome to our newest member, Leroy2027
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.