com.badlogic.gdx.scenes.scene2d.Stage.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(149)

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

Stage.getWidth介绍

[英]The viewport's world width.
[中]视口的世界宽度。

代码示例

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

/** resets {@link #startPosition} and {@link #targetPosition} */
void resetPositions () {
  startPosition.set(stage.getWidth() - stage.getWidth() / 5f, stage.getHeight() - stage.getHeight() / 5f);
  targetPosition.set(startPosition.x, stage.getHeight() / 5f);
}

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

@Override
public void resize (int width, int height) {
  super.resize(width, height);
  hud.getViewport().update(width, height, true);
  hudWidth = hud.getWidth();
  hudHeight = hud.getHeight();
}

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

/** Centers the dialog in the stage and calls {@link #show(Stage, Action)} with a {@link Actions#fadeIn(float, Interpolation)}
 * action. */
public Dialog show (Stage stage) {
  show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade)));
  setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2));
  return this;
}

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

/** Centers the dialog in the stage and calls {@link #show(Stage, Action)} with a {@link Actions#fadeIn(float, Interpolation)}
 * action. */
public Dialog show (Stage stage) {
  show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade)));
  setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2));
  return this;
}

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

float amountX = x - lastX - width;
if (width + amountX < minWidth) amountX = minWidth - width;
if (clampPosition && windowX + width + amountX > stage.getWidth()) amountX = stage.getWidth() - windowX - width;
width += amountX;

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

float amountX = x - lastX - width;
if (width + amountX < minWidth) amountX = minWidth - width;
if (clampPosition && windowX + width + amountX > stage.getWidth()) amountX = stage.getWidth() - windowX - width;
width += amountX;

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

public void validate () {
  if (!layoutEnabled) return;
  Group parent = getParent();
  if (fillParent && parent != null) {
    float parentWidth, parentHeight;
    Stage stage = getStage();
    if (stage != null && parent == stage.getRoot()) {
      parentWidth = stage.getWidth();
      parentHeight = stage.getHeight();
    } else {
      parentWidth = parent.getWidth();
      parentHeight = parent.getHeight();
    }
    setSize(parentWidth, parentHeight);
  }
  if (!needsLayout) return;
  needsLayout = false;
  layout();
}

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

public void validate () {
  if (!layoutEnabled) return;
  Group parent = getParent();
  if (fillParent && parent != null) {
    float parentWidth, parentHeight;
    Stage stage = getStage();
    if (stage != null && parent == stage.getRoot()) {
      parentWidth = stage.getWidth();
      parentHeight = stage.getHeight();
    } else {
      parentWidth = parent.getWidth();
      parentHeight = parent.getHeight();
    }
    setSize(parentWidth, parentHeight);
  }
  if (!needsLayout) return;
  needsLayout = false;
  layout();
}

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

private void setContainerPosition (Actor actor, float x, float y) {
  this.targetActor = actor;
  Stage stage = actor.getStage();
  if (stage == null) return;
  container.pack();
  float offsetX = manager.offsetX, offsetY = manager.offsetY, dist = manager.edgeDistance;
  Vector2 point = actor.localToStageCoordinates(tmp.set(x + offsetX, y - offsetY - container.getHeight()));
  if (point.y < dist) point = actor.localToStageCoordinates(tmp.set(x + offsetX, y + offsetY));
  if (point.x < dist) point.x = dist;
  if (point.x + container.getWidth() > stage.getWidth() - dist) point.x = stage.getWidth() - dist - container.getWidth();
  if (point.y + container.getHeight() > stage.getHeight() - dist) point.y = stage.getHeight() - dist - container.getHeight();
  container.setPosition(point.x, point.y);
  point = actor.localToStageCoordinates(tmp.set(actor.getWidth() / 2, actor.getHeight() / 2));
  point.sub(container.getX(), container.getY());
  container.setOrigin(point.x, point.y);
}

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

private void setContainerPosition (Actor actor, float x, float y) {
  this.targetActor = actor;
  Stage stage = actor.getStage();
  if (stage == null) return;
  container.pack();
  float offsetX = manager.offsetX, offsetY = manager.offsetY, dist = manager.edgeDistance;
  Vector2 point = actor.localToStageCoordinates(tmp.set(x + offsetX, y - offsetY - container.getHeight()));
  if (point.y < dist) point = actor.localToStageCoordinates(tmp.set(x + offsetX, y + offsetY));
  if (point.x < dist) point.x = dist;
  if (point.x + container.getWidth() > stage.getWidth() - dist) point.x = stage.getWidth() - dist - container.getWidth();
  if (point.y + container.getHeight() > stage.getHeight() - dist) point.y = stage.getHeight() - dist - container.getHeight();
  container.setPosition(point.x, point.y);
  point = actor.localToStageCoordinates(tmp.set(actor.getWidth() / 2, actor.getHeight() / 2));
  point.sub(container.getX(), container.getY());
  container.setOrigin(point.x, point.y);
}

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

public void draw (Batch batch, float parentAlpha) {
  Stage stage = getStage();
  if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this);
  keepWithinStage();
  if (style.stageBackground != null) {
    stageToLocalCoordinates(tmpPosition.set(0, 0));
    stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight()));
    drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x,
      getY() + tmpSize.y);
  }
  super.draw(batch, parentAlpha);
}

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

public void draw (Batch batch, float parentAlpha) {
  Stage stage = getStage();
  if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this);
  keepWithinStage();
  if (style.stageBackground != null) {
    stageToLocalCoordinates(tmpPosition.set(0, 0));
    stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight()));
    drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x,
      getY() + tmpSize.y);
  }
  super.draw(batch, parentAlpha);
}

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

public void keepWithinStage () {
  if (!keepWithinStage) return;
  Stage stage = getStage();
  if (stage == null) return;
  Camera camera = stage.getCamera();
  if (camera instanceof OrthographicCamera) {
    OrthographicCamera orthographicCamera = (OrthographicCamera)camera;
    float parentWidth = stage.getWidth();
    float parentHeight = stage.getHeight();
    if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom)
      setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right);
    if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom)
      setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left);
    if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom)
      setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top);
    if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom)
      setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom);
  } else if (getParent() == stage.getRoot()) {
    float parentWidth = stage.getWidth();
    float parentHeight = stage.getHeight();
    if (getX() < 0) setX(0);
    if (getRight() > parentWidth) setX(parentWidth - getWidth());
    if (getY() < 0) setY(0);
    if (getTop() > parentHeight) setY(parentHeight - getHeight());
  }
}

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

public void keepWithinStage () {
  if (!keepWithinStage) return;
  Stage stage = getStage();
  if (stage == null) return;
  Camera camera = stage.getCamera();
  if (camera instanceof OrthographicCamera) {
    OrthographicCamera orthographicCamera = (OrthographicCamera)camera;
    float parentWidth = stage.getWidth();
    float parentHeight = stage.getHeight();
    if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom)
      setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right);
    if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom)
      setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left);
    if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom)
      setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top);
    if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom)
      setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom);
  } else if (getParent() == stage.getRoot()) {
    float parentWidth = stage.getWidth();
    float parentHeight = stage.getHeight();
    if (getX() < 0) setX(0);
    if (getRight() > parentWidth) setX(parentWidth - getWidth());
    if (getY() < 0) setY(0);
    if (getTop() > parentHeight) setY(parentHeight - getHeight());
  }
}

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

private Group createActorGroup (TextureRegionDrawable bob) {
  Actor main = new DrawableActor(bob);
  main.setPosition(0, 0, Align.center);
  Actor hat = new DrawableActor(bob) {
    @Override
    public void act (float delta) {
      rotateBy(delta * -300);
    }
  };
  hat.setOrigin(Align.center);
  hat.setScale(0.5f);
  hat.setPosition(0, 21, Align.center);
  Group group = new Group() {
    @Override
    public void act (float delta) {
      rotateBy(delta * 120);
      setScale(0.9f + 0.2f * MathUtils.cos(MathUtils.degreesToRadians * getRotation()));
      super.act(delta);
    }
  };
  group.addActor(main);
  group.addActor(hat) ;
  // group.setTransform(false);
  float margin = 35;
  float x = MathUtils.random(margin, stage.getWidth() - margin);
  float y = MathUtils.random(margin, stage.getHeight() - margin);
  group.setPosition(x, y);
  group.setRotation(MathUtils.random(0, 360));
  return group;
}

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

Stage stage = getStage();
if (stage != null && parent == stage.getRoot()) {
  parentWidth = stage.getWidth();
  parentHeight = stage.getHeight();
} else {

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

Stage stage = getStage();
if (stage != null && parent == stage.getRoot()) {
  parentWidth = stage.getWidth();
  parentHeight = stage.getHeight();
} else {

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

if (actorX < 0) actorX = 0;
if (actorY < 0) actorY = 0;
if (actorX + actor.getWidth() > stage.getWidth()) actorX = stage.getWidth() - actor.getWidth();
if (actorY + actor.getHeight() > stage.getHeight()) actorY = stage.getHeight() - actor.getHeight();

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

private void createUI () {
  skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  ui = new Stage();
  String[] filters = new String[TextureFilter.values().length];
  int idx = 0;
  for (TextureFilter filter : TextureFilter.values()) {
    filters[idx++] = filter.toString();
  }
  hwMipMap = new CheckBox("Hardware Mips", skin);
  minFilter = new SelectBox(skin);
  minFilter.setItems(filters);
  magFilter = new SelectBox(skin.get(SelectBoxStyle.class));
  magFilter.setItems("Nearest", "Linear");
  Table table = new Table();
  table.setSize(ui.getWidth(), 30);
  table.setY(ui.getHeight() - 30);
  table.add(hwMipMap).spaceRight(5);
  table.add(new Label("Min Filter", skin)).spaceRight(5);
  table.add(minFilter).spaceRight(5);
  table.add(new Label("Mag Filter", skin)).spaceRight(5);
  table.add(magFilter);
  ui.addActor(table);
}

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

protected void createHUD () {
  hud = new Stage(new ScalingViewport(Scaling.fit, PREF_HUDWIDTH, PREF_HUDHEIGHT));
  hudWidth = hud.getWidth();
  hudHeight = hud.getHeight();
  skin = new Skin(Gdx.files.internal("data/uiskin.json"));

相关文章