playn.core.Graphics.createCanvas()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中playn.core.Graphics.createCanvas()方法的一些代码示例,展示了Graphics.createCanvas()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics.createCanvas()方法的具体详情如下:
包路径:playn.core.Graphics
类名称:Graphics
方法名:createCanvas

Graphics.createCanvas介绍

[英]Creates a Canvas with the specified display unit size.
[中]创建具有指定显示单元大小的画布。

代码示例

代码示例来源:origin: playn/playn

private Canvas createCanvas(int width, int height, Drawer drawer) {
 Canvas canvas = game.graphics.createCanvas(width, height);
 drawer.draw(canvas);
 return canvas;
}

代码示例来源:origin: playn/playn

/**
 * Resizes the canvas that is displayed by this layer.
 *
 * <p>Note: this throws away the old canvas and creates a new blank canvas with the desired size.
 * Thus this should immediately be followed by a {@link #begin}/{@link #end} pair which updates
 * the contents of the new canvas. Until then, it will display the old image data.
 */
public void resize (float width, float height) {
 if (canvas != null) canvas.close();
 canvas = gfx.createCanvas(width, height);
}

代码示例来源:origin: io.playn/playn-core

/** See {@link #createCanvas(float,float)}. */
public Canvas createCanvas (IDimension size) {
 return createCanvas(size.width(), size.height());
}

代码示例来源:origin: playn/playn

/** See {@link #createCanvas(float,float)}. */
public Canvas createCanvas (IDimension size) {
 return createCanvas(size.width(), size.height());
}

代码示例来源:origin: playn/playn

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());
 }
}

代码示例来源:origin: io.playn/playn-core

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;
}

代码示例来源:origin: playn/playn

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;
}

代码示例来源:origin: threerings/tripleplay

/** Creates a canvas large enough to accommodate this styled text, and renders it therein. The
 * canvas will include a one pixel border beyond the size of the styled text which is needed
 * to accommodate antialiasing. */
public Canvas toCanvas () {
  float pad = 1/_gfx.scale().factor;
  Canvas canvas = _gfx.createCanvas(width()+2*pad, height()+2*pad);
  render(canvas, pad, pad);
  return canvas;
}

代码示例来源:origin: playn/playn

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();
}

代码示例来源:origin: playn/playn

/**
  * Creates a canvas image large enough to accommodate this text block and renders the lines into
  * it. The image will include padding around the edge to ensure that antialiasing has a bit of
  * extra space to do its work.
  */
 public Canvas toCanvas(Graphics gfx, Align align, int fillColor) {
  float pad = 1/gfx.scale().factor;
  Canvas canvas = gfx.createCanvas(bounds.width()+2*pad, bounds.height()+2*pad);
  canvas.setFillColor(fillColor);
  fill(canvas, align, pad, pad);
  return canvas;
 }
}

代码示例来源:origin: io.playn/playn-core

/**
  * Creates a canvas image large enough to accommodate this text block and renders the lines into
  * it. The image will include padding around the edge to ensure that antialiasing has a bit of
  * extra space to do its work.
  */
 public Canvas toCanvas(Graphics gfx, Align align, int fillColor) {
  float pad = 1/gfx.scale().factor;
  Canvas canvas = gfx.createCanvas(bounds.width()+2*pad, bounds.height()+2*pad);
  canvas.setFillColor(fillColor);
  fill(canvas, align, pad, pad);
  return canvas;
 }
}

代码示例来源:origin: playn/playn

public DebugDrawBox2D(Platform plat, float width, float height) {
 super(new OBBViewportTransform());
 this.plat = plat;
 viewportTransform.setYFlip(true);
 strokeWidth = 1.0f;
 strokeAlpha = 255;
 fillAlpha = 150;
 canvas = plat.graphics().createCanvas(width, height);
 canvas.setStrokeWidth(strokeWidth);
 setStrokeColorFromCache();
 setFillColorFromCache();
}

代码示例来源:origin: playn/playn

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);
}

代码示例来源:origin: playn/playn

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);
 }
}

代码示例来源:origin: playn/playn

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;
}

代码示例来源:origin: playn/playn

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();
}

代码示例来源:origin: playn/playn

@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);
  }
 }
}

代码示例来源:origin: threerings/tripleplay

@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);
}

代码示例来源:origin: playn/playn

@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;
 }
}

代码示例来源:origin: playn/playn

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();
}

相关文章