views:

8

answers:

0

I have created an animation drawable and image view in my main game thread which is configured from the activity that handles the game thread (starting it etc.). My code in this handling activity looks like this:

            mDistractionsThread.animation.addFrame(getResources().getDrawable(R.drawable.one), 1000);
    mDistractionsThread.animation.addFrame(getResources().getDrawable(R.drawable.two), 1000);
    mDistractionsThread.animation.addFrame(getResources().getDrawable(R.drawable.three), 1000);
    mDistractionsThread.animation.setOneShot(false);

    mDistractionsThread.imageAnim =(ImageView) findViewById(R.id.img);
    mDistractionsThread.imageAnim.setBackgroundDrawable(mDistractionsThread.animation);


    mDistractionsThread.animation.start();

And as you can see the variable mDistractionsThread is a handle to the thread itself. This compiles fine but only displays the first frame (R.drawable.one) and does not animate at all. What is it I have missed?

I tried to set animation.start() from run() within mDistractionsThread but that just gave me an fatal exception because the View can only be altered from the class that alters its fields - which in this case is not the game thread.

How can I resolve this and get it animating through the frames, and for bonus points, moving across the x-axis?!

Many thanks