目前,我正在做简单的游戏,如外壳游戏。它在棒棒糖、棉花糖、牛油糖和KitKat 4.4.2上运行良好,但在其他KitKat版本的设备和果冻上不起作用。

移动动画代码是
public class BottomLeftToRightAnimation extends Animation {
private View view;
private float prevX,prevY;
private float cx,cy;
private float prevDx,prevDy;
private float r;
public BottomLeftToRightAnimation(View view,float r){
this.view = view;
this.r = r;
}
@Override
public boolean willChangeBounds() {
return true; // animation will change the view bounds
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
// center position of image
int cxImage = width/2;
int cyImage = height/2;
cx = view.getLeft() + cxImage;
cy = view.getTop() + cyImage;
//starting point of image rotation
prevX = cx+r;
prevY = cy;
}
// helps to get transformation between the interpolatedTime 0 to 1
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (interpolatedTime == 0){
t.getMatrix().setTranslate(prevDx,prevDy);
return;
}
float angD = (interpolatedTime * -180f) % 180;
float angR = (float) Math.toRadians(angD);
float x = (float) (cx + r * Math.cos(angR));
float y = (float) (cy + r * Math.sin(angR)/1.5);
float dx = prevX - x;
float dy = prevY - y;
prevX = x;
prevY = y;
prevDx = dx;
prevDy = dy;
t.getMatrix().setTranslate(dx,dy);
}
}以同样的方式,我为所有的旋转编写代码。我看到很多问题,像problem.The建议使用basket[1].setLayerType(View.LAYER_TYPE_HARDWARE,null);或basket[1].setLayerType(View.LAYER_TYPE_SOFTWARE,null);,但它不能修复issue.Please,帮助我修复这个错误。
发布于 2019-11-08 11:40:41
尝试设置背景层的颜色,例如#FFFFFF,以删除动画留下的鬼影图像。
https://stackoverflow.com/questions/42241877
复制相似问题