2015-06-21 68 views
-1

問題:我有一個程序,它涉及將一個條(如磚塊中斷)從一邊移到另一邊。問題是它在Eclipse中運行時以不同的速度移動,而不是導出到桌面。Eclipse程序的運行速度比導出後的要快

研究:

當讀這一點,讓我覺得,我可能無法正確創造我的差值這可以解釋爲什麼它運行在不同的速度。 my computer is carrying out java programs which i have created to fast [closed]

閱讀這篇文章後,我發現,也許的Eclipse編譯器只是更快這可能會導致在速度的差異。 Application runs faster in eclipse

// run() is being ran with a while(true) game loop 
    public void run(Input input) 
    { 
     init(); 
     // Ran at 60 FPS 
     if(fps.tick()) 
       render(); 
     // Ran as fast as possible 
     update(input); 
    } 

    private void render() 
    { 
     start = System.nanoTime();  

     if(render.getGraphics() != null) 
     { 
      Graphics g = render.getBS().getDrawGraphics(); 
      g.drawImage(new BufferedImage(Reference.WIDTH*Reference.SCALE, Reference.HEIGHT*Reference.SCALE, 
       BufferedImage.TYPE_INT_RGB), 0,0, AppGameContainer.canvas); 
      activeState.render(render.getGraphics(), AppGameContainer.canvas); 
      render.getGraphics().dispose(); 
      render.getBS().show(); 
     } 
     end = System.nanoTime(); 

     // Time in ms 
     delta = (end-start)/1000000.0; 
    } 

我如果有興趣視頻對這個問題的可視化表示:Video of issue

+0

禁用任何節流(fps.tick()),看看它是否仍然較慢。如果不是,你的代碼就是問題所在。 – tilpner

+0

另外,你真的需要每次init()嗎? – tilpner

+0

如果init方法已經完成,則返回該方法,並且不會初始化每個迭代。它是以這種方式設置的,如果它改變遊戲狀態,它將啓動新的遊戲狀態。 – user1953222

回答

-1
// run() is being ran with a while(true) game loop 
    public void run(Input input) 
    { 
     start = System.nanoTime(); 
     init(); 
     // Ran at 60 FPS 
     if(fps.tick()) 
       render(); 
     // Ran as fast as possible 
     update(input); 
     end = System.nanoTime(); 

     // Time in ms 
     delta = (end-start)/1000000.0; 
    } 

    private void render() 
    {  
     if(render.getGraphics() != null) 
     { 
      Graphics g = render.getBS().getDrawGraphics(); 
      g.drawImage(new BufferedImage(Reference.WIDTH*Reference.SCALE, Reference.HEIGHT*Reference.SCALE, 
       BufferedImage.TYPE_INT_RGB), 0,0, AppGameContainer.canvas); 
      activeState.render(render.getGraphics(), AppGameContainer.canvas); 
      render.getGraphics().dispose(); 
      render.getBS().show(); 
     } 
    } 
相關問題