I want to use the canvas.drawText() method to draw some text frame after frame. When I run my game in Java, everything is fine. But when I run in html, the behaviour is different. I isolated the code (see below) and I get the same result.
package textbug.core;
import static playn.core.PlayN.*;
import playn.core.Canvas;
import playn.core.CanvasImage;
import playn.core.Game;
import playn.core.Image;
import playn.core.ImageLayer;
public class TextBugIsolated implements Game {
Canvas canvas;
int x = 20;
@Override
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);
CanvasImage canvasImage = graphics().createImage(graphics().width(), graphics().height());
ImageLayer imageLayer = graphics().createImageLayer();
imageLayer.setImage(canvasImage);
graphics().rootLayer().add(imageLayer);
canvas = canvasImage.canvas();
}
@Override
public void paint(float alpha) {
canvas.clear();
canvas.drawText("PlayN is cool!", x++, 20);
canvas.drawText("Hello World", 20, 100);
}
@Override
public void update(float delta) {
}
@Override
public int updateRate() {
return 25;
}
}
I would expect the text “PlayN is cool!” to move horizontally like in Java but it is not. I tried to debug but I cannot step in the native code.
Anyone has a clue? Am I trying something prohibited?
This is a known issue, as documented here. It only affects the HTML backend. That seems to be exactly what you’re seeing.