Example usage for com.badlogic.gdx.scenes.scene2d Actor setX

List of usage examples for com.badlogic.gdx.scenes.scene2d Actor setX

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d Actor setX.

Prototype

public void setX(float x) 

Source Link

Usage

From source file:com.agateau.ui.UiBuilder.java

License:Apache License

protected void applyActorProperties(Actor actor, XmlReader.Element element, Group parentActor) {
    AnchorGroup anchorGroup = null;//from   w  w  w . ja  va  2 s .  com
    if (parentActor != null) {
        parentActor.addActor(actor);
        if (parentActor instanceof AnchorGroup) {
            anchorGroup = (AnchorGroup) parentActor;
        }
    }
    String attr = element.getAttribute("x", "");
    if (!attr.isEmpty()) {
        actor.setX(Float.parseFloat(attr));
    }
    attr = element.getAttribute("y", "");
    if (!attr.isEmpty()) {
        actor.setY(Float.parseFloat(attr));
    }
    attr = element.getAttribute("width", "");
    if (!attr.isEmpty()) {
        actor.setWidth(Float.parseFloat(attr));
    }
    attr = element.getAttribute("height", "");
    if (!attr.isEmpty()) {
        actor.setHeight(Float.parseFloat(attr));
    }
    attr = element.getAttribute("originX", "");
    if (!attr.isEmpty()) {
        actor.setOriginX(Float.parseFloat(attr));
    }
    attr = element.getAttribute("originY", "");
    if (!attr.isEmpty()) {
        actor.setOriginY(Float.parseFloat(attr));
    }
    attr = element.getAttribute("visible", "");
    if (!attr.isEmpty()) {
        actor.setVisible(Boolean.parseBoolean(attr));
    }
    attr = element.getAttribute("color", "");
    if (!attr.isEmpty()) {
        actor.setColor(Color.valueOf(attr));
    }
    attr = element.getAttribute("debug", "");
    if (!attr.isEmpty()) {
        if (actor instanceof Group) {
            Group group = (Group) actor;
            attr = attr.toLowerCase();
            if (attr.equals("true")) {
                group.debug();
            } else if (attr.equals("all")) {
                group.debugAll();
            }
        } else {
            actor.setDebug(Boolean.parseBoolean(attr));
        }
    }
    for (int idx = 0, size = ANCHOR_NAMES.length; idx < size; ++idx) {
        String anchorName = ANCHOR_NAMES[idx];
        attr = element.getAttribute(anchorName, "");
        if (!attr.isEmpty()) {
            if (anchorGroup == null) {
                throw new RuntimeException("Parent of " + actor + " is not an anchor group");
            }
            PositionRule rule = parseRule(attr, anchorGroup.getSpacing());
            rule.target = actor;
            rule.targetAnchor = ANCHORS[idx];
            anchorGroup.addRule(rule);
        }
    }
}

From source file:com.bagon.matchteam.mtx.utils.UtilsPositioner.java

License:Apache License

/** Advanced positioner */
private static void setPosition(Actor actorToBePositioned, float atp_W, float atp_H, float as_X, float as_Y,
        float as_XW, float as_YH, Position position) {

    // FIXME//from w w  w .jav  a2 s  .  c o m
    // No 0.0 should be used, use as_xw and others
    // Test all position later IMPORTANT !!!

    switch (position) {
    case CENTER:
        actorToBePositioned.setX((as_XW / 2.0f) - atp_W / 2.0f);
        actorToBePositioned.setY((as_YH / 2.0f) - atp_H / 2.0f);
        break;
    case SAME:
        actorToBePositioned.setPosition(as_X, as_Y);
        break;
    case LEFT:
        actorToBePositioned.setPosition(as_X, as_YH / 2.0f - atp_H / 2.0f);
        break;
    case TOP_LEFT:
        actorToBePositioned.setPosition(as_X, as_YH - atp_H);
        break;
    case TOP_LEFT_CENTER:
        actorToBePositioned.setPosition(as_X - atp_W / 2.0f, as_YH - atp_H / 2.0f);
        break;
    case TOP_RIGHT:
        actorToBePositioned.setPosition(as_XW - atp_W, as_YH - atp_H);
        break;
    case TOP_RIGHT_CENTER:
        actorToBePositioned.setPosition(as_XW - atp_W / 2.0f, as_YH - atp_H / 2.0f);
        break;
    case TOP_CENTER:
        actorToBePositioned.setPosition(as_XW / 2.0f - atp_W / 2.0f, as_YH - atp_H);
        break;
    case BOTTOM_LEFT:
        actorToBePositioned.setPosition(as_X, as_Y);
        break;
    case BOTTOM_LEFT_CENTER:
        actorToBePositioned.setPosition(as_X - atp_W / 2.0f, as_Y - atp_H / 2.0f);
        break;
    case BOTTOM_RIGHT:
        actorToBePositioned.setPosition(as_XW - atp_W, as_Y);
        break;
    case BOTTOM_RIGHT_CENTER:
        actorToBePositioned.setPosition(as_XW - atp_W / 2.0f, as_Y - atp_H / 2.0f);
        break;
    case BOTTOM_CENTER:
        actorToBePositioned.setPosition(as_XW / 2.0f - atp_W / 2.0f, as_Y);
        break;
    case RIGHT_CENTER:
        actorToBePositioned.setPosition(as_XW - atp_W, as_YH / 2.0f - atp_H / 2.0f);
        break;
    default:
        actorToBePositioned.setPosition(actorToBePositioned.getX(), actorToBePositioned.getY());
        break;
    }
}

From source file:com.centergame.starttrack.graphics.starttrack_widgets.TeamGradeWidget.java

public void init() {

    setBackgroundColor(StartTrackApp.ColorPallete.BACK);
    setWidth(Gdx.graphics.getWidth());// w w  w. j  ava2s. c o  m

    layout.paddingLeft = mp;
    layout.paddingTop = mp;
    layout.paddingBottom = sp;

    layout.addActor(
            new Text("???? ??", StartTrackApp.getResources().getLabelStyle("header")));

    if (StartTrackApp.getState().game.team_grade_required) {

        com.centergame.starttrack.graphics.starttrack_widgets.base.RadioGroup rg = new com.centergame.starttrack.graphics.starttrack_widgets.base.RadioGroup(
                0, 3, data);
        rg.paddingLeft = sp / 2;
        rg.paddingRight = sp / 2;
        rg.paddingBottom = mp;
        rg.paddingTop = mp;
        rg.setWidth(getWidth() - layout.paddingLeft - layout.paddingRight);
        rg.layout();
        layout.addActor(rg);

        Actor a = new IdpColorPixmap(StartTrackApp.ColorPallete.ELEMENT_BORDER).buildActor();
        a.setSize(getWidth() - 2 * sp, App.dp2px(2));
        Group g = new Group();
        g.setWidth(getWidth() - layout.paddingLeft - layout.paddingRight);
        g.setHeight(a.getHeight());
        g.addActor(a);
        a.setX(g.getWidth() / 2 - a.getWidth() / 2);
        layout.addActor(g);

    } else {
        Text note = new Text("? ??".toUpperCase(),
                StartTrackApp.getResources().getLabelStyle("number"));
        note.getStyle().fontColor = Color.valueOf("999999");
        layout.setGap(App.dp2px(18));
        note.setWidth(Gdx.graphics.getWidth() - layout.paddingRight - layout.paddingLeft);
        note.setAlignment(Align.center);
        layout.addActor(note);
    }

    Text participantsListTitle = new Text("? ??",
            StartTrackApp.getResources().getLabelStyle("header"));
    participantsListTitle.setPosition(lp, layout.getY() + layout.getHeight() + mp);
    layout.addActor(participantsListTitle);
}

From source file:com.jlabarca.director.ActorAccessor.java

License:Apache License

@Override
public void setValues(Actor target, int tweenType, float[] newValues) {
    switch (tweenType) {
    case POSITION_XY:
        target.setX(newValues[0]);
        target.setY(newValues[1]);/*from   ww w .ja  va  2  s  .  c  om*/
        break;
    case SCALE_XY:
        target.setScaleX(newValues[0]);
        target.setScaleY(newValues[1]);
        break;
    default:
        assert false;
    }
}

From source file:com.kotcrab.vis.ui.util.ActorUtils.java

License:Apache License

/**
 * Makes sures that actor will be fully visible in stage. If it's necessary actor position will be changed to fit it
 * on screen./* w  w w .  ja v a 2  s .com*/
 */
public static void keepWithinStage(Stage stage, Actor actor) {
    //taken from scene2d.ui Window
    Camera camera = stage.getCamera();
    if (camera instanceof OrthographicCamera) {
        OrthographicCamera orthographicCamera = (OrthographicCamera) camera;
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (actor.getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom)
            actor.setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom,
                    actor.getY(Align.right), Align.right);
        if (actor.getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom)
            actor.setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom,
                    actor.getY(Align.left), Align.left);
        if (actor.getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom)
            actor.setPosition(actor.getX(Align.top),
                    camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top);
        if (actor.getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom)
            actor.setPosition(actor.getX(Align.bottom),
                    camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom);
    } else if (actor.getParent() == stage.getRoot()) {
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (actor.getX() < 0)
            actor.setX(0);
        if (actor.getRight() > parentWidth)
            actor.setX(parentWidth - actor.getWidth());
        if (actor.getY() < 0)
            actor.setY(0);
        if (actor.getTop() > parentHeight)
            actor.setY(parentHeight - actor.getHeight());
    }
}

From source file:com.quadbits.gdxhelper.actors.CompositeActor.java

License:Apache License

@Override
public void setFlipX(boolean flipX) {
    if (flipX == this.flipX) {
        return;// w  ww. j  a  v a2s .c  om
    }

    this.flipX = flipX;

    float compositeMidPoint = getWidth() / 2f;

    Actor[] children = getChildren().begin();
    for (Actor child : children) {
        if (child instanceof FlippableActor) {
            FlippableActor flippableActor = (FlippableActor) child;
            float childX = child.getX();
            float childMidPoint = childX + child.getWidth() / 2f;
            float shift = (compositeMidPoint - childMidPoint) * 2;
            child.setX(childX + shift);

            // IMPORTANT!: invert flip on children, instead of setting whatever value
            // the 'flipX' paramenter is
            flippableActor.setFlipX(!flippableActor.isFlipX());
        }
    }
    getChildren().end();
}

From source file:com.quadbits.gdxhelper.actors.Layer.java

License:Apache License

public void setWidthCenterHorizontally(float width, boolean autoAdjustChildren) {
    setWidth(width);/*from   w  ww  .ja  va  2  s. co  m*/
    float layerX = centerHorizontally();
    setX(layerX);
    if (autoAdjustChildren) {
        for (Actor actor : getChildren()) {
            actor.setX(actor.getX() - layerX);
        }
    }
}

From source file:com.quadbits.gdxhelper.controllers.PanXOnScrollController.java

License:Apache License

@Override
public void control(Actor actor, float deltaSeconds) {
    float minX, maxX;

    if (autopan) {
        // scroll is in the [0, 1] range; actor's x should be set in the range
        // [0, Gdx.graphics.getWidth() - actor.getWidth()]
        minX = 0;//from w w  w . j  a va  2 s. com
        maxX = Gdx.graphics.getWidth() - actor.getWidth();
        if (inverted) {
            minX = maxX;
            maxX = 0;
        }
    } else {
        minX = this.minX;
        maxX = this.maxX;
    }

    actor.setX(minX + scroll * (maxX - minX));
}

From source file:com.ridiculousRPG.ui.ActorsOnStageService.java

License:Apache License

public void center(Actor actor) {
    actor.setX((int) ((getWidth() - actor.getWidth()) * .5f));
    actor.setY((int) ((getHeight() - actor.getHeight()) * .5f));
}

From source file:com.strategames.engine.tweens.ActorAccessor.java

License:Open Source License

@Override
public void setValues(Actor target, int tweenType, float[] newValues) {
    switch (tweenType) {
    case POSITION_X:
        target.setX(newValues[0]);
        break;/*from w ww  .  jav  a 2s . com*/
    case POSITION_Y:
        target.setY(newValues[0]);
        break;
    case POSITION_XY:
        target.setX(newValues[0]);
        target.setY(newValues[1]);
        break;
    case ALPHA:
        target.getColor().a = newValues[0];
        break;
    case SCALE:
        target.setScaleX(newValues[0]);
        target.setScaleY(newValues[1]);
        break;
    case ROTATE:
        target.setRotation(newValues[0]);
    default:
        assert false;
        break;
    }
}