From your question it seems like the UIImageView
is holding your monster-graphics. The more important thing however is where you located the monster-logic (that will update/move the monster-graphics).
For multiple monsters, you'll need multiple instances of the UIImageView
. Also you'll need to keep track of position and other properties (like health) for each monster. A reasonable approach to this would be to have a separate class that encapsulates all monster related logic.
Therefore, I suggest you create a special class (that inherits from NSObject
) for monster and make the UIImageView
a member of this class. A really basic interface for such a class could look like this:
#import <Foundation/Foundation.h>
@interface Monster : NSObject {
}
@property(retain) UIImageView* view;
-(void) update:(double)dt;
@end
In the init
method of your monster-class you would initialize your graphics (and assign it to the view
property). Creating multiple monsters can be done using something like this:
// constant that defines how many monsters should be created
#define NUM_MONSTERS 5
// monsters should be a member of your class, so that you can loop through it
// and perform updates. This is why we "retain" the monsters array here.
// You should use "release" to free the array in the class dealloc method.
NSMutableArray* monsters =
[[NSMutableArray arrayWithCapacity:NUM_MONSTERS] retain];
for(int i = 0; i < NUM_MONSTERS; ++i){
Monster* monster = [[Monster alloc] init];
// store the monster in the monsters array
[monsters addObject: monster];
// add the monster view (UIImageView) to the current view
[self.view addSubview: monster.view];
}