Ok, I have a game that I am working on, and I need to be able to put different character state animations onto a single view. Here I have goblin_neutral, and goblin_hit, as 2 animation lists, one to show an enemy in a calm state, and the other to show the enemy getting struck. Both are animation lists in separate .xml files in the drawable folder.
AnimationDrawable enemy_neutral_animation, enemy_hit_animation;
ImageView enemy, player;
//...after onCreate()
enemy = (ImageView)findViewById(R.id.ImageView2);
enemy.setBackgroundResource(R.drawable.goblin_neutral);
enemy_neutral_animation = (Animation)enemy.getBackground();
enemy_neutral.start();
//...now jump to the code that triggers a new animation
enemy.setBackgroundResource(R.drawable.goblin_hit);
enemy_hit_animation = (Animation)enemy.getBackground();
enemy_hit_animation.start();
// all of this works^^, as I can see the second animation displayed
// I use a timer to wait for the animation to finish
mTimer.schedule(timerTask, 600);
//mTask is where it stops everytime
timerTask = new TimerTask() {
@Override
public void run() {
enemy.setBackgroundResource(R.drawable.goblin_anim_neutral);
enemy_neutral = (AnimationDrawable)enemy.getBackground();
enemy_neutral.start();
}
};
// I get a wrong thread exception
// E/AndroidRuntime: FATAL EXCEPTION: Timer-0
ViewRootImpl$CalledFromWrongThreadException: