图像移动动画不起作用 [英] Image moving animation is not working

查看:73
本文介绍了图像移动动画不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在做一些简单的游戏,例如外壳游戏.在棒棒糖,棉花糖,牛轧糖和KitKat 4.4.2中运行良好,但在其他KitKat版本设备和Jellybean中则无法运行.

Currently i'm doing simple game like shell game. It's working good in Lollipop,Marshmallow,Nougat and KitKat 4.4.2 but not working in other KitKat version device and Jellybean.

正在移动的动画代码是

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);
}
}

我以同样的方式为所有旋转编写代码.我看到许多类似问题的问题.建议使用basket[1].setLayerType(View.LAYER_TYPE_HARDWARE,null);basket[1].setLayerType(View.LAYER_TYPE_SOFTWARE,null);,但不能解决问题.请帮助我解决此错误.

This same way i wrote code for all rotation. I saw many question like same problem.The suggested to use basket[1].setLayerType(View.LAYER_TYPE_HARDWARE,null); or basket[1].setLayerType(View.LAYER_TYPE_SOFTWARE,null); but it doesn't fix the issue.Please help me to fix this bug.

推荐答案

尝试设置背景图层的颜色,例如#FFFFFF删除动画留下的重影.

Try to set the background layer with a color e.g. #FFFFFF to remove the ghost image left behind by the animation.

这篇关于图像移动动画不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆