Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:17+00:00 2026-05-28T03:05:17+00:00

heres the problem i have 5 balls floating around the screen that bounce of

  • 0

heres the problem

i have 5 balls floating around the screen that bounce of the sides, top and bottom. thats working great.

what i want to do now is work out if any of them collide with each other.

i know about

 if (CGRectIntersectsRect(image1.frame, image2.frame)) 
{

}

but that only checks two images, i need to check all and each of them..

ive checked everywhere but cant find the answer, only others searching the same thing, any ideas?

thanks in advance

Spriggsy

edit:

im using this to find the CGRect and store it in an array

ball1 = NSStringFromCGRect(image1.frame);
ball2 = NSStringFromCGRect(image2.frame);
ball3 = NSStringFromCGRect(image3.frame);
ball4 = NSStringFromCGRect(image4.frame);
ball5 = NSStringFromCGRect(image5.frame);

bingoarray = [NSMutableArray arrayWithObjects:ball1,ball2,ball3,ball4,ball5,nil];

this then gets passed to a collision detection method

-(void)collision   {


    for (int i = 0;  i<[bingoarray count]-1 ; i++) {

        CGRect ballA = CGRectFromString([bingoarray objectAtIndex:i]);

        if (CGRectIntersectsRect(ballA, image1.frame)) {
            NSLog(@"test"); 
        }
    }

this i guess should check one ball against all the others.

so ball 1 gets checked against the others but doesnt check ball 2 against them. is this nearly there?

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:05:18+00:00Added an answer on May 28, 2026 at 3:05 am

    That is a fun little math problem to avoid being redundant.

    You can create an array of the images. And loop through it, checking if each member collides with any successive members.

    I can spell it out more with code if need be.

    EDIT I couldn’t resist

    // the images are in imagesArray
    
    //where you want to check for a collision
    
    int ballCount = [imagesArray count];
    int v1Index;
    int v2Index;
    UIImageView * v1;
    UIImageView * v2;
    for (v1Index = 0; v1Index < ballCount; v1Index++) {
      v1 = [imagesArray objectAtIndex:v1Index];
      for (v2Index = v1Index+1; v2Index < ballCount; v2Index++) {
        v2 = [imagesArray objectAtIndex:v2Index];
        if (CGRectIntersectsRect(v1.frame, v2.frame)) {
          // objects collided
          // react to collision here
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ball moving around the screen, position updated on ENTER_FRAME. My problem
so heres the problem, i have an if() statement that determines whether a user
Heres the problem. I have an app that is essentially an image gallery, it
Here's my problem: I have a virtual method defined in a .h file that
Here's my problem: I have an unmanaged dll that I made.I'm calling one of
I have a strange problem that recently appeared. At first I was loading all
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
Here's my problem: I have to call a web service with a secure header
Here's my problem.I have 2 xmlfiles with identical structure, with the second xml containing
Here's my problem: I have do create a menu/list of actions (which would be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.