Programming with SurfaceView and thread strategy for game development

后端 未结 3 915
别那么骄傲
别那么骄傲 2020-12-24 14:55

I am using a SurfaceView and a rendering thread to develop a game based on structure like LunarLander.

However, I faced many problems, and here I want to point them

3条回答
  •  长情又很酷
    2020-12-24 15:38

    I hope it can help

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    
       //if it is the first time the thread starts
       if(thread.getState() == Thread.State.NEW){
        thread.setRunning(true);//riga originale
        thread.start();//riga originale
       }
    
       //after a pause it starts the thread again
       else
       if (thread.getState() == Thread.State.TERMINATED){
           thread = new MainThread(getHolder(), this);
           thread.setRunning(true);
           thread.start();  // Start a new thread
           }
       }
    

    and this

        @Override
        protected void onPause() {
        Log.d(TAG, "Pausing...");
        MainThread.running=false;//this is the value for stop the loop in the run()
        super.onPause();
        }
    

提交回复
热议问题