javagwtplayn

SurfaceLayer is now deprecated, how to avoid using it?


I'm new to PlayN, now I'm trying to draw an image. Seems that examples on the official page (https://developers.google.com/playn/devguide/rendering) were not updated for a long time, they simply don't work with the latest version of PlayN.

I have global CanvasImage circle and SurfaceLayer surf. In my init() I have this code:

Graphics g = PlayN.graphics();
surf = g.createSurfaceLayer(g.width(), g.height());
g.rootLayer().add(surf);

And this in paint():

surf.surface().clear();
surf.surface().drawImage(circle, 0, 0);

The compiler warns that createSurfaceLayer() method is deprecated and offers to use createSurface() and createImageLayer() methods instead. How do I use it correctly?


Solution

  • I just changed SurfaceLayer surf to ImageLayer imglay, removed all the code from paint() and replaced code in init() to this:

    imglay = g.createImageLayer();
    imglay.setImage(circle);
    g.rootLayer().add(imglay);
    

    It works, but is it how it should be done?