2013-12-13 61 views
1

我使用以下代碼創建了一個小測試,並嘗試執行這些步驟以使用熱交換功能。在libGDX中使用Java的HotSwap功能

  1. 運行使用Debug按鈕
  2. 創建渲染功能一個破發點,暫停該程序的程序。
  3. 變化rectangle.width
  4. 價值編譯程序
  5. 讓重裝的IntelliJ的代碼。

但是,這似乎並沒有改變屏幕上矩形的大小。

public class HotSwapTest extends ApplicationAdapter { 
    OrthographicCamera camera; 
    ShapeRenderer shapeRenderer; 

    private static final int SCREEN_WIDTH = 800; 
    private static final int SCREEN_HEIGHT = 480; 

    Rectangle rectangle; 


    @Override 
    public void create() { 
     shapeRenderer = new ShapeRenderer(); 
     camera = new OrthographicCamera(); 
     camera.setToOrtho(false, SCREEN_WIDTH, SCREEN_HEIGHT); 

     rectangle = new Rectangle(); 
     rectangle.x = SCREEN_WIDTH/2 - 64/2; 
     rectangle.y = 20; 
     rectangle.width = 100; 
     rectangle.height = 30; 
    } 

    @Override 
    public void render() { 
     Gdx.gl.glClearColor(0, 0, 0, 1); 
     Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 

     shapeRenderer.setProjectionMatrix(camera.combined); 
     shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); 
     shapeRenderer.setColor(1, 1, 0, 1); 
     shapeRenderer.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height); 
     shapeRenderer.end(); 

     camera.update(); // only if we're moving the screen though 
    } 
} 

回答

1

在鍵入後我意識到我應該改變渲染函數中矩形的寬度。由於create函數不會再運行。

以下代碼正常工作。

public void render() { 
    Gdx.gl.glClearColor(0, 0, 0, 1); 
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 

    rectangle.width = 5; // Change this line while debugging. 
    rectangle.height = 10; 

    shapeRenderer.setProjectionMatrix(camera.combined); 
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); 
    shapeRenderer.setColor(1, 1, 0, 1); 
    shapeRenderer.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height); 
    shapeRenderer.end(); 

    camera.update(); // only if we're moving the screen though 
}