Question

I created small test, with the following code, and tried doing these steps to use the hotswap functionality.

  1. Run the program using the Debug button
  2. Create a break point in the render function, to pause the program.
  3. Change the value of rectangle.width
  4. Compile the program
  5. Let intelliJ reload the code.

But this doesn't seem to change the size of the rectangle on the screen.

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
    }
}
Was it helpful?

Solution

Realized after typing this that I should have changed the width of the rectangle in the render function. Since create function won't be run again.

The following code works properly.

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top