com.badlogic.gdx.scenes.scene2d.ui.Label类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(116)

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

Label介绍

[英]A text label, with optional word wrapping.

The preferred size of the label is determined by the actual text bounds, unless #setWrap(boolean) is enabled.
[中]文本标签,可选换行。
标签的首选大小由实际文本边界确定,除非启用了#setWrap(布尔值)。

代码示例

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

@Override
public void create () {
  if (app == null) {
    app = Gdx.app;
    tests[testIndex].create();
  }
  cameraController = new CameraInputController(tests[testIndex].camera);
  cameraController.activateKey = Keys.CONTROL_LEFT;
  cameraController.autoUpdate = false;
  cameraController.forwardTarget = false;
  cameraController.translateTarget = false;
  Gdx.input.setInputProcessor(new InputMultiplexer(cameraController, this, new GestureDetector(this)));
  font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
  hud = new Stage();
  hud.addActor(fpsLabel = new Label(" ", new Label.LabelStyle(font, Color.WHITE)));
  fpsLabel.setPosition(0, 0);
  hud.addActor(titleLabel = new Label(tests[testIndex].getClass().getSimpleName(), new Label.LabelStyle(font, Color.WHITE)));
  titleLabel.setY(hud.getHeight() - titleLabel.getHeight());
  hud.addActor(instructLabel = new Label("A\nB\nC\nD\nE\nF", new Label.LabelStyle(font, Color.WHITE)));
  instructLabel.setY(titleLabel.getY() - instructLabel.getHeight());
  instructLabel.setAlignment(Align.top | Align.left);
  instructLabel.setText(tests[testIndex].instructions);
}

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

public TextTooltip (String text, final TooltipManager manager, TextTooltipStyle style) {
  super(null, manager);
  Label label = new Label(text, style.label);
  label.setWrap(true);
  container.setActor(label);
  container.width(new Value() {
    public float get (Actor context) {
      return Math.min(manager.maxWidth, container.getActor().getGlyphLayout().width);
    }
  });
  setStyle(style);
}

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

public Payload dragStart (InputEvent event, float x, float y, int pointer) {
    Payload payload = new Payload();
    payload.setObject("Some payload!");
    payload.setDragActor(new Label("Some payload!", skin));
    Label validLabel = new Label("Some payload!", skin);
    validLabel.setColor(0, 1, 0, 1);
    payload.setValidDragActor(validLabel);
    Label invalidLabel = new Label("Some payload!", skin);
    invalidLabel.setColor(1, 0, 0, 1);
    payload.setInvalidDragActor(invalidLabel);
    return payload;
  }
});

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

public void setStyle (ButtonStyle style) {
  if (style == null) throw new NullPointerException("style cannot be null");
  if (!(style instanceof TextButtonStyle)) throw new IllegalArgumentException("style must be a TextButtonStyle.");
  super.setStyle(style);
  this.style = (TextButtonStyle)style;
  if (label != null) {
    TextButtonStyle textButtonStyle = (TextButtonStyle)style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

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

public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = tempColor.set(getColor());
  color.a *= parentAlpha;
  if (style.background != null) {
    batch.setColor(color.r, color.g, color.b, color.a);
    style.background.draw(batch, getX(), getY(), getWidth(), getHeight());
  }
  if (style.fontColor != null) color.mul(style.fontColor);
  cache.tint(color);
  cache.setPosition(getX(), getY());
  cache.draw(batch);
}

代码示例来源:origin: bladecoder/bladecoder-adventure-engine

Label msg = new Label(t.str, getUI().getSkin(), style);
msg.setWrap(true);
msg.setAlignment(Align.center, Align.center);
msg.setColor(t.color);
msg.setSize(msg.getWidth() + DPIUtils.getMarginSize() * 2, msg.getHeight() + DPIUtils.getMarginSize() * 2);
  posx = (getStage().getViewport().getScreenWidth() - msg.getWidth()) / 2;
} else if (t.y == TextManager.POS_SUBTITLE) {
  posx = DPIUtils.getMarginSize();
  posy = (getStage().getViewport().getScreenHeight() - msg.getHeight()) / 2;
} else if (t.y == TextManager.POS_SUBTITLE) {
  posy = getStage().getViewport().getScreenHeight() - msg.getHeight() - DPIUtils.getMarginSize() * 3;
} else {
  posy = unprojectTmp.y;
msg.setPosition(posx, posy);
msg.getColor().a = 0;
msg.addAction(sequence(Actions.fadeIn(0.4f, Interpolation.fade),
    Actions.delay(t.time, sequence(fadeOut(0.4f, Interpolation.fade), Actions.removeActor()))));

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

statusLabel = new Label("", skin);
statusLabel.setWrap(true);
statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
statusLabel.setAlignment(Align.center);
statusLabel.setPosition(Gdx.graphics.getWidth() * 0.5f - statusLabel.getWidth() * 0.5f, 30f);
statusLabel.setColor(Color.CYAN);
stage.addActor(statusLabel);

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

public TextButton (String text, TextButtonStyle style) {
  super();
  setStyle(style);
  this.style = style;
  label = new Label(text, new LabelStyle(style.font, style.fontColor));
  label.setAlignment(Align.center);
  add(label).expand().fill();
  setSize(getPrefWidth(), getPrefHeight());
}

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

/** Adds a new cell with a label. This may only be called if {@link Table#Table(Skin)} or {@link #setSkin(Skin)} was used. */
public Cell<Label> add (CharSequence text) {
  if (skin == null) throw new IllegalStateException("Table must have a skin set to use this method.");
  return add(new Label(text, skin));
}

代码示例来源:origin: LonamiWebs/Klooni1010

ShareScoreScreen(final Klooni game, final Screen lastScreen,
         final int score, final boolean timeMode) {
  this.game = game;
  this.lastScreen = lastScreen;
  this.score = score;
  this.timeMode = timeMode;
  final Label.LabelStyle labelStyle = new Label.LabelStyle();
  labelStyle.font = game.skin.getFont("font_small");
  infoLabel = new Label("Generating image...", labelStyle);
  infoLabel.setColor(Klooni.theme.textColor);
  infoLabel.setAlignment(Align.center);
  infoLabel.layout();
  infoLabel.setPosition(
      (Gdx.graphics.getWidth() - infoLabel.getWidth()) * 0.5f,
      (Gdx.graphics.getHeight() - infoLabel.getHeight()) * 0.5f);
  spriteBatch = new SpriteBatch();
}

代码示例来源:origin: xietansheng/Game2048ForGDX

numLabel = new Label("0", style);
numLabel.setFontScale(0.48F);
numLabel.setSize(numLabel.getPrefWidth(), numLabel.getPrefHeight());
numLabel.setX(getWidth() / 2 - numLabel.getWidth() / 2);
numLabel.setY(getHeight() / 2 - numLabel.getHeight() / 2);

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

table.add(new Label("This is regular text.", skin)).row();
table.add(new Label("This is regular text\nwith a newline.", skin)).row();
label = new Label("This is [RED]regular text\n\nwith newlines,\naligned bottom, right.", skin);
label.setColor(Color.GREEN);
label.setAlignment(Align.bottom | Align.right);
table.add(label).minWidth(200 * scale).minHeight(110 * scale).fill().row();
label = new Label("This is regular text with NO newlines, wrap enabled and aligned bottom, right.", skin);
label.setWrap(true);
label.setAlignment(Align.bottom | Align.right);
table.add(label).minWidth(200 * scale).minHeight(110 * scale).fill().row();
label = new Label("This is regular text with\n\nnewlines, wrap\nenabled and aligned bottom, right.", skin);
label.setWrap(true);
label.setAlignment(Align.bottom | Align.right);
table.add(label).minWidth(200 * scale).minHeight(110 * scale).fill().row();
table.add(new Label("This is regular text.", skin)).minWidth(200 * scale).row();
label = new Label("AAA BBB CCC DDD EEE", skin);
table.add(label).align(Align.left).row();
label = new Label("AAA B[RED]B[]B CCC DDD EEE", skin);
table.add(label).align(Align.left).row();
label = new Label("[RED]AAA [BLUE]BBB [RED]CCC [BLUE]DDD [RED]EEE", skin);
table.add(label).align(Align.left).row();

代码示例来源:origin: bladecoder/bladecoder-adventure-engine

private static void add(Stage stage, String text) {
  msg.clearActions();
  msg.setText(text);
  GlyphLayout textLayout = new GlyphLayout();
  textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true);
  msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2);
  if (!stage.getActors().contains(msg, true))
    stage.addActor(msg);
  msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2),
      Math.round((stage.getHeight() - msg.getHeight()) / 2));
  msg.invalidate();
}

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

public void next () {
  titleLabel.setText("Loading...");
  loading = 1;
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

private void prepareLabel(AssetsInterface assets) {
  Label.LabelStyle labelStyle = new Label.LabelStyle(assets.getFont(this.fontName), Color.WHITE);
  if (this.text != null) {
    this.progressText = new Label(this.text, labelStyle);
  } else {
    this.progressText = new Label("", labelStyle);
  }
  this.progressText.setWidth(this.backgroundImage.getWidth());
  this.progressText.setAlignment(Align.center);
  this.progressText.setPosition(this.backgroundImage.getX(), (this.backgroundImage.getHeight() - this.progressText.getHeight()) * 0.5f);
}

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

@Override
public void create () {
  batch = new SpriteBatch();
  skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  stage = new Stage();
  Gdx.input.setInputProcessor(stage);
  Table table = new Table();
  stage.addActor(table);
  table.setPosition(200, 65);
  Label label1 = new Label("This text is scaled 2x.", skin);
  label1.setFontScale(2);
  Label label2 = new Label(
    "This text is scaled. This text is scaled. This text is scaled. This text is scaled. This text is scaled. ", skin);
  label2.setWrap(true);
  label2.setFontScale(0.75f, 0.75f);
  table.debug();
  table.add(label1);
  table.row();
  table.add(label2).fill();
  table.pack();
}

代码示例来源:origin: xietansheng/Game2048ForGDX

public void setGameOverState(boolean isWin, int score) {
  if (isWin) {
    msgLabel.setText("恭喜您 , 游戏过关 !\n分数: " + score);
  } else {
    msgLabel.setText("游戏结束 !\n分数: " + score);
  }
  
  /*
   * 设置了文本后重新设置标签的宽高以及位置
   */
  // 标签包裹字体
  msgLabel.setSize(msgLabel.getPrefWidth(), msgLabel.getPrefHeight());
  
  msgLabel.setX(40);
  msgLabel.setY(getHeight() - msgLabel.getHeight() - 100);
}

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

@Override
public void create () {
  spriteBatch = new SpriteBatch();
  // font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false);
  font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false);
  // font = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf")).generateFont(new FreeTypeFontParameter());
  font.getData().markupEnabled = true;
  font.getData().breakChars = new char[] {'-'};
  multiPageFont = new BitmapFont(Gdx.files.internal("data/multipagefont.fnt"));
  // Add user defined color
  Colors.put("PERU", Color.valueOf("CD853F"));
  renderer = new ShapeRenderer();
  renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
  stage = new Stage(new ScreenViewport());
  Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  BitmapFont labelFont = skin.get("default-font", BitmapFont.class);
  labelFont.getData().markupEnabled = true;
  // Notice that the last [] has been deliberately added to test the effect of excessive pop operations.
  // They are silently ignored, as expected.
  label = new Label("<<[BLUE]M[RED]u[YELLOW]l[GREEN]t[OLIVE]ic[]o[]l[]o[]r[]*[MAROON]Label[][] [Unknown Color]>>", skin);
  label.setPosition(100, 200);
  stage.addActor(label);
  Window window = new Window("[RED]Multicolor[GREEN] Title", skin);
  window.setPosition(400, 300);
  window.pack();
  stage.addActor(window);
  layout = new GlyphLayout();
}

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

lighting = true;
vertexCountLabel = new Label("Vertices: 999", skin);
vertexCountLabel.setPosition(0, fpsLabel.getTop());
hud.addActor(vertexCountLabel);
textureBindsLabel = new Label("Texture bindings: 999", skin);
textureBindsLabel.setPosition(0, vertexCountLabel.getTop());
hud.addActor(textureBindsLabel);
shaderSwitchesLabel = new Label("Shader switches: 999", skin);
shaderSwitchesLabel.setPosition(0, textureBindsLabel.getTop());
hud.addActor(shaderSwitchesLabel);
drawCallsLabel = new Label("Draw calls: 999", skin);
drawCallsLabel.setPosition(0, shaderSwitchesLabel.getTop());
hud.addActor(drawCallsLabel);
glCallsLabel = new Label("GL calls: 999", skin);
glCallsLabel.setPosition(0, drawCallsLabel.getTop());
hud.addActor(glCallsLabel);
lightsLabel = new Label("Lights: 999", skin);
lightsLabel.setPosition(0, glCallsLabel.getTop());
hud.addActor(lightsLabel);

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

ui.addActor(scale);
fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
fps.setPosition(10, 30);
fps.setColor(0, 1, 0, 1);
ui.addActor(fps);

相关文章