Eclipse android - Pixel collision between sprite sheet animation and sprite
I got 2 classes SpriteSheet - this draws the sprite animations. Racheta -
this draws a normal bitmap.
I saw this - http://pastebin.com/KRX937jT
And i tried to use it like this:
public static boolean isCollisionDetected(SpriteSheet sprite1, Racheta
sprite2){
Rect bounds1 = sprite1.getBounds();
Rect bounds2 = sprite2.getBounds();
if( Rect.intersects(bounds1, bounds2) ){
Rect collisionBounds = getCollisionBounds(bounds1, bounds2);
Log.d("", String.valueOf(collisionBounds));
for (int i = collisionBounds.left; i < collisionBounds.right;
i++) {
for (int j = collisionBounds.top; j <
collisionBounds.bottom; j++) {
int sprite1Pixel = getBitmapPixel(sprite1, i, j);
int sprite2Pixel = getBitmapPixelRacheta(sprite2, i, j);
if( isFilled(sprite1Pixel) && isFilled(sprite2Pixel)) {
return true;
}
}
}
}
return false;
}
private static int getBitmapPixel(SpriteSheet sprite, int i, int j) {
return
sprite.getBitmap().getPixel((i-(int)sprite.getX())+(sprite.currentFrame-1)*(sprite.getBitmap().getWidth()/sprite.totalFrames),j-(int)sprite.getY());
// to get the pixel from the current frame in the sprite sheet. // the
sprite sheet is horizontal for the code to be easier }
public static int getBitmapPixelRacheta(Racheta sprite, int i, int j) {
int x = i - (int) sprite.getX();
int y = j - (int)sprite.getY();
return sprite.bitmap.getPixel(x, y);
}
Whenever i compile i get error 08-22 11:20:29.465: E/AndroidRuntime(1443):
java.lang.IllegalArgumentException: y must be >= 0
or 08-22 11:17:03.045: E/AndroidRuntime(1382):
java.lang.IllegalArgumentException: y must be < bitmap.height()
08-22 11:20:29.465: E/AndroidRuntime(1443): at
com.cartof.avionul.Util.getBitmapPixelRacheta(Util.java:31)
Can anyone help me?
No comments:
Post a Comment