- Code: Select all
Matrix matrix = new Matrix();
Float angle = new Double(Math.toDegrees(Math.atan2(targetY - shipY, targetX - shipX))).floatValue();
matrix.postRotate(angle + 90);
Bitmap bitmap = Bitmap.createBitmap(loader.getBitmap(mBitmap), 0, 0,
mWidth, mHeight, matrix, true);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
canvas.drawBitmap(bitmap, shipX + mX - width/2, shipY + mY - height/2, null);
It's rotating a turret bitmap to target a ship, but the rotation looks weird because it's not rotation based on a registration point that makes sense for the bitmap. Is there anyone who knows how to accomplish what I want?
Also, if anyone knows any way to improve any of the above code, it's very welcome.