my codes for the game is like this
1 2 3 4
| if(spriteA.collidesWith(bulletImage, 18,18, true)) { spriteA=null; bulletImage=null; |
the bulletImage just overlaps the sprite image
the 18 is the pixel size of the bulletImage.
Did i use this right?
collidesWith
public final boolean collidesWith(Sprite s,
boolean pixelLevel)
Checks for a collision between this Sprite and the specified Sprite.
If pixel-level detection is used, a collision is detected only if opaque pixels collide. That is, an opaque pixel in the first Sprite would have to collide with an opaque pixel in the second Sprite for a collision to be detected. Only those pixels within the Sprites' respective collision rectangles are checked.
If pixel-level detection is not used, this method simply checks if the Sprites' collision rectangles intersect.
Any transforms applied to the Sprites are automatically accounted for.
Both Sprites must be visible in order for a collision to be detected.
Parameters:
s - the Sprite to test for collision with
pixelLevel - true to test for collision on a pixel-by-pixel basis, false to test using simple bounds checking.
Returns:
true if the two Sprites have collided, otherwise false
Throws:
NullPointerException - if Sprite s is null
(Note that is from the first Google result).