2
\$\begingroup\$

I'm getting this error when I try to check if any of the targets overlap each other:

iterTargets = targets.iterator();
while (iterTargets.hasNext()) {
    Target target = iterTargets.next();

    for (Target otherTarget:targets) {
        if (target.rectangle.overlaps(otherTarget.rectangle)) {
            // do something
        }
    }
}

So I can't do that? How am I supposed to check each member of an array to see if it overlaps any other member?

\$\endgroup\$
1
\$\begingroup\$

Try the following piece of code:

for(int i = 0; i < objects.size() - 1; ++i)
    for(int j = i + 1; j < objects.size(); ++j)
        //compare obj[i] and obj[j] - check collision here
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.