Java Code Examples for com.badlogic.gdx.scenes.scene2d.Actor#setPosition()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Actor#setPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Scene2dUtils.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
public static Vector2 setPositionRelative(Actor srcActor, int srcAlign, Actor dstActor, int dstAlign, float dstX, float dstY, boolean round) {
    Vector2 pos = tmpVec2.set(srcActor.getX(srcAlign), srcActor.getY(srcAlign));

    if ((dstAlign & right) != 0)
        pos.x -= dstActor.getWidth();
    else if ((dstAlign & left) == 0)
        pos.x -= dstActor.getWidth() / 2;

    if ((dstAlign & top) != 0)
        pos.y -= dstActor.getHeight();
    else if ((dstAlign & bottom) == 0)
        pos.y -= dstActor.getHeight() / 2;

    pos.add(dstX, dstY);

    if (round) {
        pos.set(pos.x, pos.y);
    }
    dstActor.setPosition(pos.x, pos.y);
    return pos;
}
 
Example 2
Source File: PositionLmlAttribute.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    String[] values = parser.parseArray(rawAttributeData, actor);
    if (values.length != 2) {
        parser.throwError("There must be exactly 2 values in the array");
    }
    try {
        actor.setPosition(
                Float.parseFloat(values[0]),
                Float.parseFloat(values[1]));
    } catch (NumberFormatException e) {
        parser.throwError("Can't read position values from the array.", e);
    }
}
 
Example 3
Source File: LabelManager.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(int entityId) {
  tmpVec2.set(mPosition.get(entityId).position);
  iso.toScreen(tmpVec2);

  Label label = mLabel.get(entityId);
  tmpVec2.add(label.offset);

  Actor actor = label.actor;
  actor.setPosition(tmpVec2.x, tmpVec2.y, Align.center | Align.bottom);
  labels.add(actor);
}
 
Example 4
Source File: GameScreen.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void setDetails(Actor details, Item item, Actor parent, Actor slot) {
  if (this.details == details) return;
  this.details = details;
  if (slot != null) {
    details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY() + slot.getHeight(), Align.bottom | Align.center);
    tmpVec2.set(details.getX(), details.getY());
    parent.localToStageCoordinates(tmpVec2);
    tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
    tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
    details.setPosition(tmpVec2.x, tmpVec2.y);
    tmpVec2.set(slot.getX(), slot.getY());
    parent.localToStageCoordinates(tmpVec2);
    if (details.getY() < tmpVec2.y + slot.getHeight()) {
      details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY(), Align.top | Align.center);
      tmpVec2.set(details.getX(), details.getY());
      parent.localToStageCoordinates(tmpVec2);
      tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
      tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
      details.setPosition(tmpVec2.x, tmpVec2.y);
    }
  } else {
    details.setPosition(item.getX() + item.getWidth() / 2, item.getY(), Align.top | Align.center);
    tmpVec2.set(details.getX(), details.getY());
    parent.localToStageCoordinates(tmpVec2);
    tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
    tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
    details.setPosition(tmpVec2.x, tmpVec2.y);
  }
}
 
Example 5
Source File: MenuTools.java    From Cubes with MIT License 5 votes vote down vote up
public static void arrangeX(float y, boolean centerY, Actor... actors) {
  float w = GUI_WIDTH / actors.length;
  for (int i = 0; i < actors.length; i++) {
    Actor a = actors[i];
    a.setPosition(((i + 0.5f) * w) - (a.getWidth() / 2f), y - (centerY ? (a.getWidth() / 2f) : 0));
  }
}
 
Example 6
Source File: MenuTools.java    From Cubes with MIT License 5 votes vote down vote up
public static void arrangeY(float x, boolean centerX, Actor... actors) {
  float w = (GUI_HEIGHT / (actors.length + 1));
  for (int i = 0; i < actors.length; i++) {
    Actor a = actors[i];
    a.setPosition(x - (centerX ? (a.getWidth() / 2f) : 0), ((i + 0.5f) * w) - (a.getHeight() / 2f));
  }
}
 
Example 7
Source File: WidgetParser.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
/**
 * 解析子控件
 */
public Group widgetChildrenParse(CocoStudioUIEditor editor,
                                 ObjectData widget, Group parent, Actor actor) {
    Table table = new Table();
    table.setClip(widget.isClipAble());
    table.setName(actor.getName());

    Scale scale = widget.getScale();

    if (scale != null) {
        table.setScale(scale.getScaleX(), scale.getScaleY());
    }

    table.setRotation(actor.getRotation());
    table.setVisible(actor.isVisible());

    table.setTouchable(widget.isTouchEnable() ? Touchable.enabled
        : Touchable.childrenOnly);

    // editor.getActors().get(actor.getName()).removeValue(actor, true);
    //
    // addActor(editor, table, option);

    actor.setVisible(true);
    actor.setTouchable(Touchable.disabled);

    if (scale != null || widget.getRotation() != 0) {
        table.setTransform(true);
    }

    table.setSize(actor.getWidth(), actor.getHeight());
    table.setPosition(actor.getX(), actor.getY());

    // 锚点就是子控件的锚点

    Scale anchorPoint = widget.getAnchorPoint();
    if (anchorPoint != null) {

        table.setOrigin(anchorPoint.getScaleX() * table.getWidth(),
            anchorPoint.getScaleY() * table.getHeight());
    }
    for (ObjectData childrenWidget : widget.getChildren()) {
        Actor childrenActor = editor.parseWidget(table, childrenWidget);
        if (childrenActor == null) {
            continue;
        }
        table.addActor(childrenActor);
    }
    sort(widget, table);

    // Widget的位置应该与Table重合.相当于Widget的属性被移植到了Table
    actor.setPosition(0, 0);
    actor.setScale(1, 1);
    table.addActorAt(0, actor);
    return table;
}
 
Example 8
Source File: BaseWidgetParser.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
/**
 * common attribute parser
 * according cocstudio ui setting properties of the configuration file
 *
 * @param editor
 * @param widget
 * @param parent
 * @param actor
 * @return
 */
public Actor commonParse(CocoStudioUIEditor editor, ObjectData widget,
                         Group parent, Actor actor) {
    this.editor = editor;
    actor.setName(widget.getName());
    actor.setSize(widget.getSize().getX(), widget.getSize().getY());
    // set origin
    if (widget.getAnchorPoint() != null) {
        actor.setOrigin(widget.getAnchorPoint().getScaleX() * actor.getWidth(),
            widget.getAnchorPoint().getScaleY() * actor.getHeight());
    }

    //判空,因为新版本的单独节点没有Postion属性
    if (widget.getPosition() != null) {
        actor.setPosition(widget.getPosition().getX() - actor.getOriginX(),
            widget.getPosition().getY() - actor.getOriginY());
    }

    // CocoStudio的编辑器ScaleX,ScaleY 会有负数情况
    //判空,因为新版本的单独节点没有Scale属性
    if (widget.getScale() != null) {
        actor.setScale(widget.getScale().getScaleX(), widget.getScale()
            .getScaleY());
    }

    if (widget.getRotation() != 0) {// CocoStudio 是顺时针方向旋转,转换下.
        actor.setRotation(360 - widget.getRotation() % 360);
    }
    //添加倾斜角
    if (widget.getRotationSkewX() != 0 && widget.getRotationSkewX() == widget.getRotationSkewY()) {
        actor.setRotation(360 - widget.getRotationSkewX() % 360);
    }

    // 设置可见
    actor.setVisible(widget.isVisibleForFrame());

    Color color = editor.getColor(widget.getCColor(), widget.getAlpha());

    actor.setColor(color);

    actor.setTouchable(deduceTouchable(actor, widget));

    // callback

    addCallback(actor, widget);
    // callback

    addActor(editor, actor, widget);

    if (widget.getChildren() == null || widget.getChildren().size() == 0) {
        //添加Action
        parseAction(actor, widget);

        return actor;
    }

    return null;
}
 
Example 9
Source File: ActorUtils.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public static void centerAt(@NonNull Actor a, float x, float y) {
  a.setPosition(x - a.getWidth() / 2, y - a.getHeight() / 2);
}
 
Example 10
Source File: PieMenu.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void show(InteractiveActor a, float x, float y) {
	setVisible(true);
	this.x = x;
	this.y = y;
	iActor = a;

	// DRAW TARGET DESCRIPTION
	desc = iActor.getDesc();

	if (desc != null) {

		if (desc.charAt(0) == I18N.PREFIX)
			desc = sceneScreen.getWorld().getI18N().getString(desc.substring(1));

		layout.setText(font, desc);
	}

	Actor rightButton;

	if (a.getVerb("talkto") != null) {
		talktoButton.setVisible(true);
		pickupButton.setVisible(false);
		rightButton = talktoButton;
	} else {
		talktoButton.setVisible(false);
		pickupButton.setVisible(true);
		rightButton = pickupButton;
	}

	float margin = DPIUtils.getMarginSize();

	// FITS TO SCREEN
	if (x < lookatButton.getWidth() + margin)
		this.x = lookatButton.getWidth() + margin;
	else if (x > viewportWidth - lookatButton.getWidth() - margin)
		this.x = viewportWidth - lookatButton.getWidth() - margin;

	if (y < margin)
		this.y = margin;
	else if (y > viewportHeight - lookatButton.getHeight() - margin)
		this.y = viewportHeight - lookatButton.getHeight() - margin;

	// lookatButton.setPosition(this.x - lookatButton.getWidth() - margin / 2,
	// this.y + margin);
	lookatButton.setPosition(this.x - lookatButton.getWidth() / 2, this.y - lookatButton.getHeight() / 2);
	lookatButton.addAction(Actions.moveTo(this.x - lookatButton.getWidth() - margin / 2, this.y + margin, .1f));

	// rightButton.setPosition(this.x + margin / 2, this.y + margin);
	rightButton.setPosition(this.x - lookatButton.getWidth() / 2, this.y - lookatButton.getHeight() / 2);
	rightButton.addAction(Actions.moveTo(this.x + margin / 2, this.y + margin, .1f));

}
 
Example 11
Source File: MenuTools.java    From Cubes with MIT License 4 votes vote down vote up
public static void setPos(float x, float y, Actor... actors) {
  for (Actor o : actors) {
    o.setPosition(x, y);
  }
}
 
Example 12
Source File: MenuTools.java    From Cubes with MIT License 4 votes vote down vote up
public static void center(Actor actor) {
  actor.setPosition((GUI_WIDTH / 2) - (actor.getWidth() / 2), (GUI_HEIGHT / 2) - (actor.getHeight() / 2));
}
 
Example 13
Source File: MenuTools.java    From Cubes with MIT License 4 votes vote down vote up
public static void center(Actor... actors) {
  for (Actor actor : actors) {
    actor.setPosition((GUI_WIDTH / 2) - (actor.getWidth() / 2), (GUI_HEIGHT / 2) - (actor.getHeight() / 2));
  }
}