public Label(float wid, float hei, TextFormat format) { layer = new CanvasLayer(game.graphics, wid, hei); this.format = format; }
public Hud (SceneGame game) { _game = game; layer = new CanvasLayer(game.plat.graphics(), 1, 1); }
/** Ensures that the canvas image is at least the specified dimensions and cleared to all * transparent pixels. Also creates and adds the image layer to the parent layer if needed. */ public void prepare (Graphics gfx, float width, float height) { CanvasLayer layer = _layer; if (layer == null) { layer = new CanvasLayer(gfx, width, height); if (_depth != null) layer.setDepth(_depth); _parent.add(layer); _layer = layer; } else if (layer.width() < width || layer.height() < height) { // TODO: should we ever shrink it? layer.resize(width, height); } _preparedWidth = width; _preparedHeight = height; }
@Override public void init() { CanvasLayer actions = new CanvasLayer(game.graphics, 300, 300); float x = 50, y = 50; Sound fanfare = loadSound("sounds/fanfare"); float ffx = addButton("Play Fanfare", x, y, () -> { fanfare.play(); addAction(actions, "Played Fanfare."); }); Sound lfanfare = loadSound("sounds/fanfare"); lfanfare.setLooping(true); addLoopButtons(actions, "Fanfare", lfanfare, ffx, y); y += 50; Sound bling = loadSound("sounds/bling"); bling.setLooping(true); addLoopButtons(actions, "Bling", bling, x, y); y += 50; Sound music = loadMusic("sounds/music"); music.setLooping(true); addLoopButtons(actions, "Music", music, x, y); y += 50; game.rootLayer.addAt(actions, x, y); }
@Override public void init() { CanvasLayer clayer = new CanvasLayer(game.graphics, game.graphics.viewSize); game.rootLayer.add(clayer); conns.add(game.update.connect(clock -> { Canvas canvas = clayer.begin(); canvas.clear(); canvas.setStrokeWidth(3); canvas.setStrokeColor(0x88ff0000); noSegs += direction; if (noSegs > 50) direction = -1; if (noSegs < 20) direction = 1; float r = 100; for (int ii = 0; ii < noSegs; ii++) { float angle = 2*FloatMath.PI * ii / noSegs; IDimension viewSize = game.plat.graphics().viewSize; float x = (r * FloatMath.cos(angle)) + viewSize.width() / 2; float y = (r * FloatMath.sin(angle)) + viewSize.height() /2; canvas.strokeCircle(x, y, 100); } clayer.end(); // reupload the image data })); } }
addTestLayer("ImageLayer repeat x/y", 100, 100, new ImageLayer(reptex).setSize(100, 100)); time = new CanvasLayer(game.graphics, 100, 100); addTestLayer("updated canvas", 100, 100, time);