0

I'm moving a bitmap along a path on a Canvas. The path has various curves and the bitmap follows along. pm.getMatrix does a really lovely job of handling the position and rotation adjustments along the path when its passed the PathMeasure.POSITION_MATRIX_FLAG and TANGENT_MATRIX_FLAG, however, it rotates the bitmap pivoted on the 0,0 coordinate. I need it to pivot on the center of the bitmap.

I cracked open the matrix in the debugger, and it appears that there is indeed *no spoon. There is however 3 arrays of floats, each containing 3 floats. I'm guessing that if I can get those values, I can probably figure out which of them describes the rotation of the object, and there's probably some way to alter the pivot point? I see no other way to do it... Would love some guidance on at least what those three float arrays actually describe.

PathMeasure pm = new PathMeasure(playerPath, false);
float fSegmentLen = pm.getLength() / numSteps;
Matrix mxTransform = new Matrix();

pm.getMatrix(fSegmentLen * iCurStep, mxTransform,
                    PathMeasure.POSITION_MATRIX_FLAG + PathMeasure.TANGENT_MATRIX_FLAG );
canvas.drawBitmap(playerCar, mxTransform, null);
4

1 回答 1

4

尝试这个:

private void setDrawingMatrix(float distance) {
    pm.getMatrix(distance, mxTransform, PathMeasure.POSITION_MATRIX_FLAG | PathMeasure.TANGENT_MATRIX_FLAG);
    mxTransform.preTranslate(-playerCar.getWidth() / 2.0f, -playerCar.getHeight() / 2.0f);
}

然后在 onDraw 方法中:

canvas.drawBitmap(playerCar, mxTransform, null);

开开心心...

于 2013-06-04T21:52:07.530 回答