Hi!

I am programming a game with the following quellcode.
I am just using ImageView's which I move around and I have to handle
some touch events.
What do I have to change to have the highest framerate?

If I remove this block
                                        try
                                        {
                                                Thread.sleep(45);
                                        }
                                        catch(InterruptedException ex) {}
the graphics don't get painted and I see nothing.
If I do NOT remove this block, the graphics get painted but I do not
have the hightest framerate and the graphic is stuttering.

How can I solve this problem?
Greetings, Martin


-----------------------------------------------------------------------------------
Here is the quellcode:





//package ........

//imports...

public class LeonardFrog extends Activity implements FrogLanded
{


        //declaration of variables...

        private OnTouchListener jumpListener = new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {

                // do something...

                return true;
            }
        };


        @Override
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);

                setContentView(R.layout.main);
                updatePhysicsDraw();

                (new Thread(new AnimationLoop())).start();
        }


        private synchronized void updatePhysics()
        {

                // This function calculates all new positions of ImageView's

        }




        public void onDraw ()
        {
                // This function moves many ImageView's around
        }


        private Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                        Global.calculating=true;
                        updatePhysics();
                        onDraw();
                        Global.calculating=false;

                }
        };

        class AnimationLoop implements Runnable
        {
                public void run()
                {
                        while(true)
                        {
                                while(running)
                                {
                                        try
                                        {
                                                Thread.sleep(45);
                                        }
                                        catch(InterruptedException ex) {}

                                        if (!Global.calculating)
                                                handler.sendEmptyMessage(0);
                                }
                        }
                }
        }

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to