无法让 Canvas/CanvasLayer 在 Playn 中工作
就像标题所说,我无法让 Canvas/CanvasLayer 在 PlayN 中工作。我的示例代码再简单不过了。 ImageLayer 和默认背景加载良好(该代码已在此处注释掉),但画布实际上始终不可见。
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);
}
我正在使用 PlayN 1.0.3 和 Maven。请注意,这是针对纯 java 编译的。
蒂亚·丹尼尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的颜色代码是错误的,您还必须指定 alpha
0x000000
实际上意味着 00 alpha, 00 red, 00 gren试试这个:
testCanvas.setStrokeColor(Color.rgb(0, 0, 0) ));
或者如果您想要 50% 透明度:
testCanvas.setStrokeColor(Color.argb(0x80, 0, 0, 0));
您可能还想在添加 CanvasLayer 之前添加背景:
Your color codes are wrong, you must specify alpha as well
0x000000
actually 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: