Search code examples
playn

Graphics2D awt port of copyArea method to playn


I'm porting an old awt java game to playn framework, I've some graphics.copyArea calls.. there is some way to map this call into some play.core.Canvas calls ?

Thanks


Solution

  • You should be able to use the same canvas as the source and destination of a Canvas.drawImage call:

    CanvasImage image = graphics().createImage(100, 100);
    // draw stuff in your canvas image
    
    // define the source of the copyArea: 15x15+5+5
    float sx = 5, sy = 5, swidth = 15, sheight = 15;
    // note that we use swidth/sheight for dwidth/dheight because we don't want to scale,
    // we just want to copy data from one place in the image to another
    image.canvas().drawImage(image, 25, 25, swidth, sheight, sx, sy, swidth, sheight);
    

    However, if you're really rendering everything to a Canvas on every frame, you're probably going to discover that that's very slow. You'll be better off restructuring things to use ImageLayer and other constructs that can be hardware accelerated.