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.
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
You access objects in an NSArray with objectAtIndex: array[i] is for C arrays.
for (int i = 0; i < num_perches; i++) { CGRect perchFrame = [(UIView *)[percharray objectAtIndex:i] frame]; if (CGRectIntersectsRect(bird.frame, perchFrame)) { code her } }
Just one last one as it still relates to the array When a bird is shot, I wish to rotate it 180 so it hangs upsidedown. (the birds are also in an array)
Replies
<li
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomearray[i] is for C arrays.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomeand how to use the array to set new centers for the perches :confused:
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeCan you be more specific about the second question?
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomein header file NSMutableArray *percharray;
then @property (nonatomic, retain) NSMutableArray *parcharray;
In M file in viewDidLoad
This runs OK but is not detecting a collision?
second question sorted
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeYou then have to release it in dealloc.
For the second part, just use setCenter: on the view.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeJust one last one as it still relates to the array
When a bird is shot, I wish to rotate it 180 so it hangs upsidedown.
(the birds are also in an array)
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome