Animation works fine when i create object of AnimatedVectorDrawable in MainActivity onCreate(), but when i try same in SurfaceView it just shows first frame and not animate at all. Also i need to add that mutate() not working for me either, but i don't need it, so i mention it just for you know.
I already tried literally everything.
public class MainGamePanel extends SurfaceView implements SurfaceHolder.Callback {
MainThread thread;
AnimatedVectorDrawableCompat animation;
public MainGamePanel(Context context) {
super(context);
getHolder().addCallback(this);
thread = new MainThread("test", getHolder(), this);
animation = (AnimatedVectorDrawableCompat) AnimatedVectorDrawableCompat.create(getContext(), R.drawable.ic_animated_ghost);
animation.start();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
thread.start();
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
canvas.drawColor(Color.GRAY);
animation.setBounds(100, 500, 600, 1000);
animation.draw(canvas);
}
}
If for some reason it is impossible to animate vector in SurfaceView, can someone tell me how to workaround it? Like cover SurfaceView canvas with transparent layout that would animate vector on it? Thanks!
I literally read everything what i found in google, but i'm still confused. Im pretty sure that i seen games using vectors so i think it should be possible...