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

x33g5p2x  于2022-01-16 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(112)

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

Actor.localToStageCoordinates介绍

[英]Transforms the specified point in the actor's coordinates to be in the stage's coordinates.
[中]将演员坐标中的指定点转换为舞台坐标。

代码示例

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

/** Converts coordinates for this actor to those of another actor, which can be anywhere in the stage. */
public Vector2 localToActorCoordinates (Actor actor, Vector2 localCoords) {
  localToStageCoordinates(localCoords);
  return actor.stageToLocalCoordinates(localCoords);
}

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

/** Converts coordinates for this actor to those of another actor, which can be anywhere in the stage. */
public Vector2 localToActorCoordinates (Actor actor, Vector2 localCoords) {
  localToStageCoordinates(localCoords);
  return actor.stageToLocalCoordinates(localCoords);
}

代码示例来源: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: stackoverflow.com

public static Vector2 getStageLocation(Actor actor) {
  return actor.localToStageCoordinates(new Vector2(0, 0));
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

/** Converts coordinates for this actor to those of another actor, which can be anywhere in the stage. */
public Vector2 localToActorCoordinates (Actor actor, Vector2 localCoords) {
  localToStageCoordinates(localCoords);
  return actor.stageToLocalCoordinates(localCoords);
}

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

public static Vector2 getStageLocation(Actor actor) {
  return actor.localToStageCoordinates(new Vector2(0, 0));
}

代码示例来源:origin: narfman0/GDXWorld

/** @param actor the actor which position in stage coordinates to return
 *  @return the position of the given actor in the stage coordinate system */
public static Vector2 positionInStageCoordinates(Actor actor) {
  if(actor.hasParent())
    actor.localToStageCoordinates(tmp.set(0, 0));
  else
    tmp.set(actor.getX(), actor.getY());
  return tmp;
}

代码示例来源:origin: langurmonkey/gaiasky

/**
 * Shows menu below (or above if not enough space) given actor.
 * @param stage stage instance that this menu is being added to
 * @param actor used to get calculate menu position in stage, menu will be displayed above or below it
 */
public void showMenu(Stage stage, Actor actor) {
  Vector2 pos = actor.localToStageCoordinates(tmpVector.setZero());
  float menuY;
  if (pos.y - getHeight() <= 0) {
    menuY = pos.y + actor.getHeight() + getHeight() - 5;
  } else {
    menuY = pos.y + 5;
  }
  showMenu(stage, pos.x, menuY);
}

代码示例来源:origin: kotcrab/vis-ui

/**
 * Shows menu below (or above if not enough space) given actor.
 * @param stage stage instance that this menu is being added to
 * @param actor used to get calculate menu position in stage, menu will be displayed above or below it
 */
public void showMenu (Stage stage, Actor actor) {
  Vector2 pos = actor.localToStageCoordinates(tmpVector.setZero());
  float menuY;
  if (pos.y - getHeight() <= 0) {
    menuY = pos.y + actor.getHeight() + getHeight() - sizes.borderSize;
  } else {
    menuY = pos.y + sizes.borderSize;
  }
  showMenu(stage, pos.x, menuY);
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

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: kotcrab/vis-ui

@Override
public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) {
  if (pointer == -1) {
    Vector2 targetPos = target.localToStageCoordinates(new Vector2());
    setX(targetPos.x + (target.getWidth() - getWidth()) / 2);
    float tooltipY = targetPos.y - getHeight() - 6;
    float stageHeight = target.getStage().getHeight();
    //is there enough space to display above widget?
    if (stageHeight - tooltipY > stageHeight)
      setY(targetPos.y + target.getHeight() + 6); //display above widget
    else
      setY(tooltipY); //display below
    displayTask.cancel();
    Timer.schedule(displayTask, appearDelayTime);
  }
}

代码示例来源:origin: kotcrab/vis-ui

private void getStageCoordinatesWithinParent (final InputEvent event) {
  final Actor parent = mimic.getActor().getParent();
  if (parent != null) {
    MIMIC_COORDINATES.set(Vector2.Zero);
    parent.localToStageCoordinates(MIMIC_COORDINATES);
    final float parentX = MIMIC_COORDINATES.x;
    final float parentY = MIMIC_COORDINATES.y;
    final float parentEndX = parentX + parent.getWidth();
    final float parentEndY = parentY + parent.getHeight();
    MIMIC_COORDINATES.set(event.getStageX() + offsetX, event.getStageY() + offsetY);
    if (MIMIC_COORDINATES.x < parentX) {
      MIMIC_COORDINATES.x = parentX;
    } else if (MIMIC_COORDINATES.x + mimic.getWidth() > parentEndX) {
      MIMIC_COORDINATES.x = parentEndX - mimic.getWidth();
    }
    if (MIMIC_COORDINATES.y < parentY) {
      MIMIC_COORDINATES.y = parentY;
    } else if (MIMIC_COORDINATES.y + mimic.getHeight() > parentEndY) {
      MIMIC_COORDINATES.y = parentEndY - mimic.getHeight();
    }
    STAGE_COORDINATES.set(MathUtils.clamp(event.getStageX(), parentX, parentEndX - 1f),
        MathUtils.clamp(event.getStageY(), parentY, parentEndY - 1f));
  } else {
    getStageCoordinatesWithOffset(event);
  }
}

代码示例来源:origin: kotcrab/vis-ui

if (parent != null) {
  MIMIC_COORDINATES.set(Vector2.Zero);
  parent.localToStageCoordinates(MIMIC_COORDINATES);
  final float parentX = MIMIC_COORDINATES.x;
  final float parentY = MIMIC_COORDINATES.y;

相关文章