mutable array - fill with objects - draw to view
Hi guys,
needing some help for something im clearly underseeing.
In the jist of it i am trying to implement a bowling app for iphone all i UIview
I need to know how the best way to fill an array i have called:
NSMutableArray *pinArray;
with ten pin objects?
i am doing like so :
all i want to do with them now, is use the 1 image i have set up in interface builder and apply this to ten of the pins, and draw them at relevant parts on the screen.
I intend not to be lazy and just add ten images to the screen each of its own class.
thanks for the help guys, all i want is to have this working so i can use object collision with a ball and move them on collision.. thanks
needing some help for something im clearly underseeing.
In the jist of it i am trying to implement a bowling app for iphone all i UIview
I need to know how the best way to fill an array i have called:
NSMutableArray *pinArray;
with ten pin objects?
i am doing like so :
Code:
-(void) fillArray
{
for (int i =0; i<10; i++) {
[pinArray addObject:m_pin];
}
}all i want to do with them now, is use the 1 image i have set up in interface builder and apply this to ten of the pins, and draw them at relevant parts on the screen.
I intend not to be lazy and just add ten images to the screen each of its own class.
thanks for the help guys, all i want is to have this working so i can use object collision with a ball and move them on collision.. thanks
You can't take one object and add it to an array 10 times -- well, you can, but you still only have one object with one position that only gets drawn once. You want to do something more like this:
That will create 10 new UIImageViews, attach then to the current view for this controller, and add them to your array.
Code:
-(void) fillArray {
UIImage *pinImage = [UIImage imageNamed:@"pin.png"];
for (int i =0; i<10; i++) {
UIImageView *m_pin = [[UIImageView alloc] initWithImage: pinImage];
[self.view addSubview: m_pin];
[pinArray addObject:m_pin];
[m_pin release];
}
}That will create 10 new UIImageViews, attach then to the current view for this controller, and add them to your array.
-- Available Now: Dead Panic, a casual zombie shooter!
-- Development Blog: How to make a game under $1k
-- Twitter: xsmasher
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Array of Objects in C++ | Tekkan | 9 | 7,904 |
Dec 12, 2007 04:13 PM Last Post: scgames |
|
| memcpy(stuct array pointer struct array point) | unknown | 22 | 8,815 |
Sep 29, 2005 03:16 PM Last Post: unknown |
|

