Is it possible to detect when an object and a bitmap collide. I have an arraylist of sprites that I am shooting with an image. I tried using this method here but as soon as the bitmap appears the sprite disappears, this is in the Sprite class:

public boolean isCollision(Bitmap other)
    if(other.getWidth() > x && other.getWidth() < x + width && >other.getHeight() > y && other.getHeight() < y + height);
    return true;

2 Answers 2


You have two major, basic problems. First, this won't even compile because of this part: && >other.getHeight() > y && (notice the > before other). Secondly, this:

return true;

will always return true. What you probably meant was this:

    return true;
return false;

which, since something is just a boolean expression, is the same as

return something;

Both Eclipse and Netbeans have an "AutoFormat" option that would have made this error immediately obvious, while simultaneously fixing your horrendous formatting.

After you fix those, you still have problems with your logic, but those at least can be easily discovered with a debugger.


The following statement will always be false:

other.getWidth() > x && other.getWidth() < x

x can not be both greater and smaller than width.

As for the rest of your question, it seems to be two folded. You seem to be both having problem with checking the collision and with displaying it.

To solve your collision problems I would need to know more. What kind of collision do you want? (Should sprites collide with a background image that is divided into two colors, red for collidable?) And how are you handling sprite-sprite collisions currently?

To solve your displaying problem I would need to see more of your drawing functions.

(on an other note, who keeps upping every question asked on gamdev even if they are short unclear questions?)

  • \$\begingroup\$ I want to detect if they have collided, whether one is changing colors or if theirs a counter that increments every time they collide doesn't matter. As long as I can tell that the system recognizes the collision. I have bitmap images that are created and move randomly when the trackball is pressed. \$\endgroup\$
    – MarkEz
    Commented Jun 25, 2011 at 22:12
  • \$\begingroup\$ So the bitmaps should just be seen as rectangles? (With the color thingey, I meant for example that it should collide only with one color, which is often used for complex shapes) \$\endgroup\$
    – Roy T.
    Commented Jun 26, 2011 at 7:42
  • \$\begingroup\$ Yes, if possible \$\endgroup\$
    – MarkEz
    Commented Jun 28, 2011 at 21:31
  • 1
    \$\begingroup\$ You overlooked a bit: other.getWidth() > x && other.getWidth() < x + width That's assuming the question wasn't edited without a history after you posted this. \$\endgroup\$ Commented Jul 6, 2011 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .