Search code examples
javaawtscalepaintgraphics2d

BufferStrategy not scaling Graphics2D


I am currently trying to program a simple platform game. I would like to scale the graphics up by a factor of 2/4/whatever so that I can get an old-school look and feel from the game. However, when I call scale on my Graphics2D instance, nothing happens.

@Override
public void paint(Graphics g) {

    BufferStrategy bf = this.getBufferStrategy();

    Graphics2D bfg = (Graphics2D) bf.getDrawGraphics();

    mLevel.draw(bfg, this);

    for (GameEntity entity : mGameEntities) {
        entity.draw(bfg, this);
    }

    bfg.scale(2.0, 2.0);

    bf.show();

}

The draw calls basically just end up calling g.drawImage(..). Everything else is drawn correctly, so I do not understand why it isn't scaling everything up by a factor of 2.


Solution

  • @MadProgrammer was correct - one must scale the Graphics2D instance before making any draw calls.

    @Override
    public void paint(Graphics g) {
    
        BufferStrategy bf = this.getBufferStrategy();
    
        Graphics2D bfg = (Graphics2D) bf.getDrawGraphics();
    
        bfg.scale(2.0, 2.0);
    
        mLevel.draw(bfg, this);
    
        for (GameEntity entity : mGameEntities) {
            entity.step();
            entity.draw(bfg, this);
        }
    
    
    
        bf.show();
    
    }