我目前正在开发一款2D Android 游戏,
在这个游戏中,一个视图对象(位图)在抛物线路径上在屏幕上移动,就像在这个图像中一样,但是这个路径是静态的,静态路径是通过画布上的手指绘制的,
与签名图相同。
此静态路径上的位图移动代码是
//animation step
private static int iMaxAnimationStep = 900;
private int iCurStep = 0;
private Path ptCurve = new Path(); //curve
private PathMeasure pm; //curve measure
private float fSegmentLen; //curve segment length
//init smooth curve
PointF point = aPoints.get(0);
ptCurve.moveTo(point.x, point.y);
for(int i = 0; i < aPoints.size() - 1; i++){
point = aPoints.get(i);
PointF next = aPoints.get(i+1);
ptCurve.quadTo(point.x, point.y, (next.x + point.x) / 2, (point.y + next.y) / 2);
}
pm = new PathMeasure(ptCurve, false);
fSegmentLen = pm.getLength() / iMaxAnimationStep;//20 animation steps
//animate the Bitmap
Matrix mxTransform = new Matrix();
if (iCurStep <= iMaxAnimationStep)
{
pm.getMatrix(fSegmentLen * iCurStep, mxTransform,
PathMeasure.POSITION_MATRIX_FLAG);
mxTransform.preTranslate(-Bitmap.getWidth(), -Bitmap.getHeight());
canvas.drawBitmap(Bitmap, mxTransform, null);
iCurStep++; //advance to the next step
mPauseViewHandler.post(mPauseViewRunnable);
} else {
iCurStep = 0;
}
但我的问题是我想在动态路径(抛物线)上移动这个视图对象(位图) ,并且动态曲线路径将在任何设备中工作。
我已经搜索了很多,但我找不到解决方案如何获取动态路径(抛物线曲线)。
帮助!如果您对这篇文章有任何解决方案、建议、想法、教程,我们将不胜感激。