Like the title says, I can’t get Canvas/CanvasLayer working in PlayN. My sample code couldn’t be simpler. The ImageLayer and default background loads fine (that code is commented out here), but the canvas is practically invisible always.
public void init() {
// create and add background image layer
//Image bgImage = assetManager().getImage("images/bg.png");
//ImageLayer bgLayer = graphics().createImageLayer(bgImage);
//graphics().rootLayer().add(bgLayer);
graphics().setSize(500, 400);
CanvasLayer testLayer = graphics().createCanvasLayer(200,200);
Canvas testCanvas = testLayer.canvas();
graphics().rootLayer().add(testLayer);
//testCanvas.clear();
testCanvas.setStrokeColor(0x000000);
testCanvas.setStrokeWidth(2);
testCanvas.setFillColor(0xff0000);
testCanvas.drawText("hello", 50, 50);
testCanvas.drawLine(0, 0, 300,300);
testCanvas.strokeRect(1, 1, 46, 46);
//I even tried adding this.
testLayer.setAlpha(1);
testLayer.setVisible(true);
testLayer.setScale(1);
}
I’m using PlayN 1.0.3 with Maven. Note this is for the pure java compilation.
TIA Daniel
Your color codes are wrong, you must specify alpha as well
0x000000actually means 00 alpha, 00 red, 00 grentry this instead:
testCanvas.setStrokeColor(Color.rgb(0, 0, 0));or if you want 50% transparency:
testCanvas.setStrokeColor(Color.argb(0x80, 0, 0, 0));you might also want to add a background as well, before you add your CanvasLayer: