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

  • SEARCH
  • Home
  • 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 9241355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:21:30+00:00 2026-06-18T08:21:30+00:00

I am making an explosion. The explosion is supposed to hit all the enemys

  • 0

I am making an explosion. The explosion is supposed to hit all the enemys within it’s rectangle (x, y, x + w, y + h). Both the explosion and the enemies inherits from a Sprite class that has a getBounds() method that returns their rectangle. When I create the explosion item I in the constructor loops trough the enemies to check if the rectangles intersects with rectangle.intersects(rectangle2). But seemingly when there are multiple targets that are SUPPOSED to be intersected sometimes the check ignores some of them…

Here’s som code:
In the constructor of the class Explosion, inherits class Sprite

    List<Zombie> zombies = mGamePlay.getZombieHandeler().getZombies();
    Rect r = getBounds();

    for(int i = 0; i < zombies.size(); i++)
    {
        Rect zR = zombies.get(i).getAnimation().getBounds();

        if(!zombies.get(i).isDead() && r.intersect(zR))
            zombies.get(i).doDamage(new int[]{damage, 0, 0});
    }

Inside class Sprite:

public Rect getBounds()
{
    return new Rect(mPosX, mPosY, mPosX + mWidth, mPosY + mHeight);
}
  • 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-06-18T08:21:31+00:00Added an answer on June 18, 2026 at 8:21 am

    Rect.intersect() will modify the source rectangle and set it to the intersection of the two rectangles if they intersect. This is mentioned in the javadoc. This means that after the first successful intersection test, subsequent intersection tests will likely fail (they will pass only for zombies that intersect each other with the original intersection rectangle.)

    Instead you should use the Rect.intersects() (with an ‘s’ at the end.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching for some good tutorial about making simple sprite animation from few
Making an adobe flex ui in which data that is calculated must use proprietary
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
Making websites that appear correctly in IE is a big problem. Is there any
Making a form that will accept a bunch of textual data and an image
Making good progress on rails now, but hit a snag on heroku deployment. After
Making an uno game for a project. all 108 cards are located in a
Making a quick JQuery demo where clicking a table element changes it from black
making an Access database (2003) that is mainly used by other programmers and tech
Making a ruby on rails application for a class, and we are not allowed

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.