mutable array - fill with objects - draw to view

burrows111
Unregistered
 
Post: #1
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 :
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 Smile
Quote this message in a reply
Member
Posts: 27
Joined: 2008.12
Post: #2
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:

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
Quote this message in a reply
burrows111
Unregistered
 
Post: #3
thanks smasher - ill give it a bash!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Array of Objects in C++ Tekkan 9 9,858 Dec 12, 2007 04:13 PM
Last Post: scgames
  memcpy(stuct array pointer struct array point) unknown 22 10,889 Sep 29, 2005 03:16 PM
Last Post: unknown