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

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

Introduction

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

Prototype

public void setY(float y) 

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 ww w  .  j av  a2s .  c om
    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 . j  a va  2 s .  co  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.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]);//www  . ja v a 2 s  .  c  o  m
        target.setY(newValues[1]);
        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./*from   ww w  . jav  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 setFlipY(boolean flipY) {
    if (flipY == this.flipY) {
        return;/*w  w w .  jav a  2 s .co m*/
    }

    this.flipY = flipY;

    float compositeMidPoint = getHeight() / 2f;

    Actor[] children = getChildren().begin();
    for (Actor child : children) {
        if (child instanceof FlippableActor) {
            FlippableActor flippableActor = (FlippableActor) child;
            float childY = child.getY();
            float childMidPoint = childY + child.getHeight() / 2f;
            float shift = (compositeMidPoint - childMidPoint) * 2;
            child.setY(childY + shift);

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

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

License:Apache License

public void setHeightCenterVertically(float height, boolean autoAdjustChildren) {
    setHeight(height);//  w  w  w. ja v  a2  s . c  om
    float layerY = centerVertically();
    setY(layerY);
    if (autoAdjustChildren) {
        for (Actor actor : getChildren()) {
            actor.setY(actor.getY() - layerY);
        }
    }
}

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

License:Apache License

@Override
public void control(Actor actor, float deltaSeconds) {
    float minY, maxY;

    if (autopan) {
        // scroll is in the [0, 1] range; actor's y should be set in the range
        // [0, Gdx.graphics.getHeight() - actor.getHeight()]
        minY = 0;/*  w  ww  .  j  a  v a2 s. c om*/
        maxY = Gdx.graphics.getHeight() - actor.getHeight();
        if (inverted) {
            minY = maxY;
            maxY = 0;
        }
    } else {
        minY = this.minY;
        maxY = this.maxY;
    }

    actor.setY(minY + scroll * (maxY - minY));
}

From source file:com.redthirddivision.astilade.render.tweens.ActorAccessor.java

License:Apache License

@Override
public void setValues(Actor target, int type, float[] newValues) {
    switch (type) {
    case TweenTypes.ALPHA:
        target.setColor(target.getColor().r, target.getColor().g, target.getColor().g, newValues[0]);
        break;/*w w w  . j  av  a2 s .c  om*/
    case TweenTypes.RGB:
        target.setColor(newValues[0], newValues[1], newValues[2], target.getColor().a);
        break;
    case TweenTypes.Y:
        target.setY(newValues[0]);
        break;
    case TweenTypes.SIZE:
        target.setScale(newValues[0], newValues[1]);
        break;
    default:
        assert false;
    }
}

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.screens.AbstractScreen.java

License:Open Source License

/**
 * Called to create the animation when screen is displayed
 * @return Timeline timeline that contains the animation(s) or null to disable animation
 *///from w w w  .  j a v  a  2 s  .  com
protected Timeline showAnimation() {
    Timeline timelineParallel = Timeline.createParallel();
    Timeline timelineSequence = Timeline.createSequence();
    Stage stage = getStageUIActors();

    if (this.title != null) {
        this.title.setY(stage.getHeight() + this.title.getHeight());
        timelineParallel.push(Tween.to(this.title, ActorAccessor.POSITION_Y, 0.4f).target(700));
    }

    if (this.menuButton != null) {
        this.menuButton.setY(stage.getHeight() + this.menuButton.getHeight());
        timelineParallel.push(Tween.to(this.menuButton, ActorAccessor.POSITION_Y, 0.4f).target(700));
    }

    Array<Actor> actors = stage.getActors();

    /**
     * Hiding will move actors out of screen. If we want to re-show
     * the screen we need to know where they were originally.
     */
    if (this.originalPositions == null) {
        this.originalPositions = new Array<Vector2>(actors.size);
        for (int i = 0; i < actors.size; i++) {
            Actor actor = actors.get(i);
            this.originalPositions.add(new Vector2(actor.getX(), actor.getY()));
        }
    }

    for (int i = 0; i < actors.size; i++) {
        Actor actor = actors.get(i);
        if ((actor != this.title) && (actor != this.menuButton)) {
            Vector2 pos = this.originalPositions.get(i);
            actor.setY(-60f);
            timelineSequence.push(Tween.to(actor, ActorAccessor.POSITION_Y, 0.1f).target(pos.y));
        }
    }

    timelineParallel.push(timelineSequence);
    return timelineParallel;
}