playn.core.Graphics类的使用及代码示例

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

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

Graphics介绍

[英]Provides access to graphics information and services.
[中]提供对图形信息和服务的访问。

代码示例

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

  1. protected void updateDisplay() {
  2. StringBuffer buf = new StringBuffer();
  3. if (notifications.isEmpty()) {
  4. buf.append("No notifications. Pause and resume the game to generate some.");
  5. } else {
  6. buf.append("Notifications:\n");
  7. for (String note : notifications)
  8. buf.append(note).append("\n");
  9. }
  10. TextLayout layout = game.graphics.layoutText(buf.toString(), new TextFormat());
  11. Canvas canvas = game.graphics.createCanvas(layout.size);
  12. canvas.setFillColor(0xFF000000).fillText(layout, 0, 0);
  13. layer.setTile(canvas.toTexture());
  14. }
  15. }

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

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

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

  1. /** Creates a texture surface which is {@code width x height} in display units.
  2. * A managed backing texture will be automatically created. */
  3. public TextureSurface (Graphics gfx, QuadBatch defaultBatch, float width, float height) {
  4. this(gfx, defaultBatch, gfx.createTexture(width, height, Texture.Config.DEFAULT));
  5. }

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

  1. public Label(float wid, float hei, TextFormat format) {
  2. image = graphics().createImage(wid, hei);
  3. layer = graphics().createImageLayer(image);
  4. this.format = format;
  5. }

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

  1. @Override
  2. public void init() {
  3. CanvasImage canvasImage = graphics().createImage(graphics().width(), graphics().height());
  4. canvas = canvasImage.canvas();
  5. graphics().rootLayer().add(graphics().createImageLayer(canvasImage));
  6. }

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

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

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

  1. protected void addInfo (CanvasImage image, float cx, float y) {
  2. TextLayout ilayout = graphics().layoutText(image.width() + "x" + image.height(), infoFormat);
  3. CanvasImage iimage = graphics().createImage(ilayout.width(), ilayout.height());
  4. iimage.canvas().setFillColor(0xFF000000).fillText(ilayout, 0, 0);
  5. graphics().rootLayer().addAt(graphics().createImageLayer(iimage), cx - iimage.width()/2, y);
  6. }

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

  1. protected Texture makeTextImage() {
  2. TextFormat format = new TextFormat(new Font(font.value(), style.value(), 24));
  3. float wrapWidth = wrap.value() == 0 ?
  4. Float.MAX_VALUE : game.graphics.viewSize.width()*wrap.value()/100;
  5. TextBlock block = new TextBlock(
  6. game.graphics.layoutText(sample, format, new TextWrap(wrapWidth)));
  7. float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height());
  8. float pad = 1/game.graphics.scale().factor;
  9. Canvas canvas = game.graphics.createCanvas(awidth+2*pad, aheight+2*pad);
  10. canvas.translate(pad, pad);
  11. canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight);
  12. render(canvas, block, align.value(), lineBounds.value());
  13. return canvas.toTexture();
  14. }

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

  1. public void render(Surface surf) {
  2. surf.setFillColor(0xFFFFFFFF).fillRect(0, 0, graphics().width(), graphics().height());
  3. }
  4. });

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

  1. protected void updateDisplay() {
  2. StringBuffer buf = new StringBuffer();
  3. if (notifications.isEmpty()) {
  4. buf.append("No notifications. Pause and resume the game to generate some.");
  5. } else {
  6. buf.append("Notifications:\n");
  7. for (String note : notifications)
  8. buf.append(note).append("\n");
  9. }
  10. TextLayout layout = graphics().layoutText(buf.toString(), new TextFormat());
  11. CanvasImage image = graphics().createImage(layout.width(), layout.height());
  12. image.canvas().setFillColor(0xFF000000);
  13. image.canvas().fillText(layout, 0, 0);
  14. layer.setImage(image);
  15. }
  16. }

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

  1. public Span (Graphics gfx, String text, TextStyle style) {
  2. super(gfx, text, style);
  3. _layout = gfx.layoutText(text, style);
  4. }

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

  1. protected Image makeTextImage() {
  2. TextFormat format = new TextFormat(graphics().createFont(font.value(), style.value(), 24), true);
  3. float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : graphics().width()*wrap.value()/100;
  4. TextBlock block = new TextBlock(graphics().layoutText(sample, format, new TextWrap(wrapWidth)));
  5. float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height());
  6. float pad = TextBlock.pad();
  7. CanvasImage image = graphics().createImage(awidth+2*pad, aheight+2*pad);
  8. image.canvas().translate(pad, pad);
  9. image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight);
  10. render(image.canvas(), block, align.value(), lineBounds.value());
  11. return image;
  12. }

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

  1. @Override public void init() {
  2. Canvas canvas = game.graphics.createCanvas(2*r, 2*r);
  3. canvas.setFillColor(0xFF99CCFF).fillCircle(r, r, r);
  4. fragment("CanvasImage", canvas.toTexture(), 250, 160);
  5. Texture subtex = game.graphics.createTexture(
  6. otile.width(), otile.height(), Texture.Config.DEFAULT.repeat(true, true));
  7. new TextureSurface(game.graphics, game.defaultBatch, subtex).begin().
  8. Canvas split = game.graphics.createCanvas(orange.width(), orange.height());
  9. split.draw(orange.region( 0, 0, phw, phh), phw, phh);
  10. split.draw(orange.region(phw, 0, phw, phh), 0, phh);

代码示例来源:origin: com.googlecode.playn/playn-tests-core

  1. private void addTestLayer(int width, int height, Layer layer) {
  2. // if this layer won't fit in this row, wrap down to the next
  3. if (nextX + width > graphics().width()) {
  4. nextY += (maxY + GAP);
  5. nextX = GAP;
  6. maxY = 0;
  7. }
  8. layer.setTranslation(nextX, nextY);
  9. graphics().rootLayer().add(layer);
  10. // update our positioning info
  11. nextX += (width + GAP);
  12. maxY = Math.max(maxY, height);
  13. }

代码示例来源:origin: stackoverflow.com

  1. @Override
  2. public void paintComponent(Graphics g)
  3. {
  4. g.scale(zoomFactor, zoomFactor);
  5. // Change the size of the panel
  6. setSize(origWidth * zoomFactor, origHeight * zoomFactor);
  7. // Re-Layout the panel
  8. validate();
  9. super.paintComponent(g);
  10. }

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

  1. @Override
  2. public void init() {
  3. GroupLayer rootLayer = graphics().rootLayer();
  4. CanvasImage image = graphics().createImage(250, 25);
  5. image.canvas().drawText(rootLayer.getClass().getName(), 0, 15);
  6. ImageLayer info = graphics().createImageLayer(image);
  7. info.setTranslation(5, 5);
  8. rootLayer.add(info);
  9. int[] depths = { 0, -1, 1, 3, 2, -4, -3, 4, -2 };
  10. int[] fills = { 0xFF99CCFF, 0xFFFFFF33, 0xFF9933FF, 0xFF999999, 0xFFFF0033,
  11. 0xFF00CC00, 0xFFFF9900, 0xFF0066FF, 0x0FFCC6666 };
  12. int width = 200, height = 200;
  13. for (int ii = 0; ii < depths.length; ii++) {
  14. int depth = depths[ii];
  15. image = graphics().createImage(width, height);
  16. image.canvas().setFillColor(fills[ii]);
  17. image.canvas().fillRect(0, 0, width, height);
  18. image.canvas().setFillColor(0xFF000000);
  19. image.canvas().drawText(depth + "/" + ii, 5, 15);
  20. ImageLayer layer = graphics().createImageLayer(image);
  21. layer.setDepth(depth);
  22. layer.setTranslation(225-50*depth, 125+25*depth);
  23. rootLayer.add(layer);
  24. }
  25. }
  26. }

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

  1. void displayMenu() {
  2. clearTest();
  3. clearRoot();
  4. GroupLayer root = graphics().rootLayer();
  5. root.add(createWhiteBackground());
  6. if (graphics().ctx() == null) {
  7. info += "canvas";
  8. } else {
  9. info += "gl (quads=" + graphics().ctx().quadShaderInfo() + " tris=" +
  10. graphics().ctx().trisShaderInfo() + ")";
  11. graphics().rootLayer().addAt(graphics().createImageLayer(infoImg), x, y);
  12. y += infoImg.height() + gap;
  13. if (x + button.width() > graphics().width() - gap) {
  14. x = gap;
  15. y += maxHeight + gap;

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

  1. protected ImageLayer createLabel(String text, GroupLayer parent,
  2. int fg, int bg, float x, float y, float padding) {
  3. TextLayout layout = graphics().layoutText(text, baseFormat);
  4. float twidth = layout.width() + padding * 2;
  5. float theight = layout.height() + padding * 2;
  6. CanvasImage image = graphics().createImage(twidth, theight);
  7. if (bg != 0) {
  8. image.canvas().setFillColor(bg);
  9. image.canvas().fillRect(0, 0, twidth, theight);
  10. }
  11. image.canvas().setFillColor(fg);
  12. image.canvas().fillText(layout, padding, padding);
  13. ImageLayer imageLayer = graphics().createImageLayer(image);
  14. imageLayer.setTranslation(x, y);
  15. parent.add(imageLayer);
  16. return imageLayer;
  17. }

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

  1. @Override public void init () {
  2. GroupLayer slider = graphics().createGroupLayer();
  3. CanvasImage image = graphics().createImage(WIDTH + 10, HEIGHT);
  4. image.canvas().setFillColor(0xff808080);
  5. image.canvas().fillRect(0, 0, WIDTH + 10, HEIGHT);
  6. ImageLayer bg = graphics().createImageLayer(image);
  7. slider.add(bg);
  8. image = graphics().createImage(WIDTH, HWIDTH);
  9. image.canvas().setFillColor(0xffffffff);
  10. image.canvas().fillRect(0, 0, WIDTH, HWIDTH);
  11. image.canvas().setStrokeColor(0xff000000);
  12. image.canvas().drawLine(0, HWIDTH / 2, WIDTH, HWIDTH / 2);
  13. image.canvas().setStrokeColor(0xffff0000);
  14. image.canvas().strokeRect(0, 0, WIDTH - 1, HWIDTH - 1);
  15. slider.add(il = graphics().createImageLayer(image));
  16. il.setOrigin(0, HWIDTH / 2);
  17. il.setTranslation(0, HEIGHT / 2);
  18. il.setDepth(1);
  19. graphics().rootLayer().add(slider);
  20. slider.setTranslation(25, 25);
  21. bg.addListener(new Mouse.LayerAdapter() {
  22. @Override public void onMouseWheelScroll (WheelEvent event) {
  23. float y = il.ty() + event.velocity();
  24. y = Math.max(0, Math.min(y, HEIGHT));
  25. il.setTranslation(0, y);
  26. }
  27. });
  28. }

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

  1. protected ImageLayer createLabel(String text, int bg, float x, float y) {
  2. return createLabel(text, graphics().rootLayer(), 0xFF202020, bg, x, y, 0);
  3. }

相关文章