Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Using an Array for collision detection

kev1953kev1953 Posts: 26Registered Users
edited July 2011 in iPhone SDK Development
I have a game where a bird files to a number of perches,
I need to detect a collision with the perch
Rather then using a load of if statements, I would like to refer to them in an array.
if (CGRectIntersectsRect(bird.frame, perch1.frame)) { }
if (CGRectIntersectsRect(bird.frame, perch2.frame)) { }
if (CGRectIntersectsRect(bird.frame, perch3.frame)) { } and so on……

NSMutableArray* percharray = [NSMutableArray array];
[percharray addObject:perch1]; // Smilie is a Colon ?
[percharray addObject:perch2];
[percharray addObject:perch3];
... etc

for (int i = 0; i < num_perches; i++) {
if (CGRectIntersectsRect(bird.frame, percharray[i].frame)) { code her }
}

But I get error

‘struct NSMutbleArray’ has no member named ‘frame’

Any help please :confused:
Post edited by kev1953 on

Replies

Sign In or Register to comment.