/** Calls {@link #toTexture(Texture.Config)} with the default texture config. */ public Texture toTexture () { return toTexture(Texture.Config.DEFAULT); }
/** Calls {@link #toTexture(Texture.Config)} with the default texture config. */ public Texture toTexture () { return toTexture(Texture.Config.DEFAULT); }
protected void updateDisplay() { StringBuffer buf = new StringBuffer(); if (notifications.isEmpty()) { buf.append("No notifications. Pause and resume the game to generate some."); } else { buf.append("Notifications:\n"); for (String note : notifications) buf.append(note).append("\n"); } TextLayout layout = game.graphics.layoutText(buf.toString(), new TextFormat()); Canvas canvas = game.graphics.createCanvas(layout.size); canvas.setFillColor(0xFF000000).fillText(layout, 0, 0); layer.setTile(canvas.toTexture()); } }
Texture colorTex () { if (colorTex == null) { Canvas canvas = createCanvas(1, 1); canvas.setFillColor(0xFFFFFFFF).fillRect(0, 0, canvas.width, canvas.height); colorTex = canvas.toTexture(Texture.Config.UNMANAGED); } return colorTex; }
Texture colorTex () { if (colorTex == null) { Canvas canvas = createCanvas(1, 1); canvas.setFillColor(0xFFFFFFFF).fillRect(0, 0, canvas.width, canvas.height); colorTex = canvas.toTexture(Texture.Config.UNMANAGED); } return colorTex; }
private void addTestCanvas(String descrip, int width, int height, Drawer drawer) { Canvas canvas = createCanvas(width, height, drawer); addTestLayer(descrip, width, height, new ImageLayer(canvas.toTexture())); }
public Texture wrapText(String text, float width, TextBlock.Align align) { TextLayout[] layouts = game.graphics.layoutText(text, TEXT_FMT, new TextWrap(width)); Canvas canvas = new TextBlock(layouts).toCanvas(game.graphics, align, 0xFF000000); return canvas.toTexture(); }
protected Texture makeLabel(String label) { TextLayout layout = game.graphics.layoutText(label, new TextFormat()); Canvas canvas = game.graphics.createCanvas(layout.size); canvas.setFillColor(0xFF000000).fillText(layout, 0, 0); return canvas.toTexture(); }
@Override public ImageLayer toLayer (ImageLayer target) { Canvas canvas = toCanvas(); target.setTile(canvas.toTexture()); target.setTranslation(style.effect.offsetX(), style.effect.offsetY()); return target; }
@Override protected void createParticles (ParticleBatch batch, Randoms rando) { Canvas image = graphics().createCanvas(7, 7); image.setFillColor(0xFFFFFFFF); image.fillCircle(3, 3, 3); Tile tile = image.toTexture(); Emitter emitter = new Emitter(batch, paint, 5000, tile); emitter.generator = Generator.constant(100); emitter.initters.add(Lifespan.constant(5)); emitter.initters.add(Color.constant(0xFF99CCFF)); emitter.initters.add(Transform.layer(emitter.layer)); emitter.initters.add(Velocity.randomSquare(rando, -20, 20, -100, 0)); emitter.effectors.add(new Gravity(30)); emitter.effectors.add(new Move()); emitter.effectors.add(Alpha.byAge(Interpolator.EASE_OUT, 1, 0)); emitter.layer.setTranslation(size().width()/2, size().height()/2); add(emitter); } }
private void addTestCanvas(String descrip, int width, int height, String imagePath, ImageDrawer drawer) { Canvas target = game.graphics.createCanvas(width, height); ImageLayer layer = new ImageLayer().setSize(width, height); game.assets.getImage(imagePath).state.onSuccess(image -> { drawer.draw(target, image); layer.setTile(target.toTexture()); }); addTestLayer(descrip, width, height, layer); }
protected void addInfo (Canvas canvas, float cx, float y) { TextFormat infoFormat = new TextFormat(new Font("Helvetica", 12)); TextLayout ilayout = game.graphics.layoutText(canvas.width + "x" + canvas.height, infoFormat); Canvas iimage = game.graphics.createCanvas(ilayout.size); iimage.setFillColor(0xFF000000).fillText(ilayout, 0, 0); game.rootLayer.addAt(new ImageLayer(iimage.toTexture()), cx - iimage.width/2, y); } }
protected ImageLayer createLabel(String text, GroupLayer parent, int fg, int bg, float x, float y, float padding) { TextLayout layout = game.graphics.layoutText(text, baseFormat); float twidth = layout.size.width() + padding * 2; float theight = layout.size.height() + padding * 2; Canvas canvas = game.graphics.createCanvas(twidth, theight); if (bg != 0) canvas.setFillColor(bg).fillRect(0, 0, twidth, theight); canvas.setFillColor(fg).fillText(layout, padding, padding); ImageLayer imageLayer = new ImageLayer(canvas.toTexture()); parent.addAt(imageLayer, x, y); return imageLayer; }
public Texture formatText (TextFormat format, String text, boolean border) { TextLayout layout = game.graphics.layoutText(text, format); float margin = border ? 10 : 0; float width = layout.size.width()+2*margin, height = layout.size.height()+2*margin; Canvas canvas = game.graphics.createCanvas(width, height); if (border) canvas.setFillColor(0xFFCCCCCC).fillRect(0, 0, canvas.width, canvas.height); canvas.setFillColor(0xFF000000).fillText(layout, margin, margin); if (border) canvas.setStrokeColor(0xFF000000).strokeRect(0, 0, width-1, height-1); return canvas.toTexture(); }
@Override public void init() { int[] depths = { 0, -1, 1, 3, 2, -4, -3, 4, -2 }; int[] fills = { 0xFF99CCFF, 0xFFFFFF33, 0xFF9933FF, 0xFF999999, 0xFFFF0033, 0xFF00CC00, 0xFFFF9900, 0xFF0066FF, 0x0FFCC6666 }; int width = 200, height = 200; for (int ii = 0; ii < depths.length; ii++) { int depth = depths[ii]; Canvas canvas = game.graphics.createCanvas(width, height); canvas.setFillColor(fills[ii]).fillRect(0, 0, width, height); canvas.setFillColor(0xFF000000).drawText(depth + "/" + ii, 5, 15); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setDepth(depth).setTranslation(225-50*depth, 125+25*depth); game.rootLayer.add(layer); } } }
protected Entity createBullet (float x, float y, float vx, float vy, float angle, int exps) { Entity bullet = create(true); bullet.add(type, sprite, opos, pos, vel, radius, expires); Canvas canvas = graphics().createCanvas(5, 2); canvas.setFillColor(0xFFFFFFFF).fillRect(0, 0, 5, 2); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setOrigin(2.5f, 1); layer.setRotation(angle); int id = bullet.id; type.set(id, BULLET); sprite.set(id, layer); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, vx, vy); radius.set(id, 2); expires.set(id, exps); return bullet; }
@Override protected Instance instantiate (final IDimension size) { Canvas canvas = _gfx.createCanvas(size); if (_borderWidth > 0) { canvas.setFillColor(_borderColor).fillRoundRect( 0, 0, size.width(), size.height(), _radius); // scale the inner radius based on the ratio of the inner height to the full height; // this improves the uniformity of the border substantially float iwidth = size.width() - 2*_borderWidth, iheight = size.height() - 2*_borderWidth; float iradius = _borderRadius * (iheight / size.height()); canvas.setFillColor(_bgColor).fillRoundRect( _borderWidth, _borderWidth, iwidth, iheight, iradius); } else { canvas.setFillColor(_bgColor).fillRoundRect(0, 0, size.width(), size.height(), _radius); } ImageLayer layer = new ImageLayer(canvas.toTexture()); return new LayerInstance(size, layer); }
@Override public void init() { String text = "The quick brown fox jumped over the lazy dog."; TextFormat format = new TextFormat(new Font("Helvetica", 18)); TextBlock block = new TextBlock(game.graphics.layoutText(text, format, new TextWrap(100))); float x = 5; for (float scale : new float[] { 1f, 2f, 3f }) { float swidth = block.bounds.width() * scale, sheight = block.bounds.height() * scale; Canvas canvas = game.graphics.createCanvas(swidth, sheight); canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, swidth-0.5f, sheight-0.5f); canvas.scale(scale, scale); canvas.setFillColor(0xFF000000); block.fill(canvas, TextBlock.Align.RIGHT, 0, 0); game.rootLayer.addAt(new ImageLayer(canvas.toTexture()), x, 5); addInfo(canvas, x + swidth/2, sheight + 10); x += swidth + 5; } }
protected Entity createShip (float x, float y) { Entity ship = create(true); ship.add(type, sprite, opos, pos, vel, spin, radius); Canvas canvas = graphics().createCanvas(30, 20); Path path = canvas.createPath(); path.moveTo(0, 0).lineTo(30, 10).lineTo(0, 20).close(); canvas.setFillColor(0xFFCC99FF).fillPath(path); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setOrigin(15, 10); layer.setRotation(-MathUtil.HALF_PI); int id = ship.id; type.set(id, SHIP); sprite.set(id, layer); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, 0, 0); radius.set(id, 10); return ship; }
protected Texture makeTextImage() { TextFormat format = new TextFormat(new Font(font.value(), style.value(), 24)); float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : game.graphics.viewSize.width()*wrap.value()/100; TextBlock block = new TextBlock( game.graphics.layoutText(sample, format, new TextWrap(wrapWidth))); float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height()); float pad = 1/game.graphics.scale().factor; Canvas canvas = game.graphics.createCanvas(awidth+2*pad, aheight+2*pad); canvas.translate(pad, pad); canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight); render(canvas, block, align.value(), lineBounds.value()); return canvas.toTexture(); }