Example usage for com.badlogic.gdx.scenes.scene2d Group addActor

List of usage examples for com.badlogic.gdx.scenes.scene2d Group addActor

Introduction

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

Prototype

public void addActor(Actor actor) 

Source Link

Document

Adds an actor as a child of this group.

Usage

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

License:Apache License

public RefreshHelper(Group group) {
    Actor helperActor = new Actor() {
        @Override/* www  .  j a v  a 2  s.  c o  m*/
        public void setStage(Stage stage) {
            super.setStage(stage);
            installEventListener(stage);
        }
    };
    group.addActor(helperActor);
}

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.j a v  a2 s.  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.ahsgaming.superrummy.screens.LevelScreen.java

License:Apache License

public Group popupMessage(String text, String icon, float duration) {
    Gdx.app.log(LOG, "Popup message!");
    Group popup = new Group();
    Label lbl = new Label(text, getSkin(), "medium");
    Image img = new Image(game.textureService.createSprite(icon));
    popup.addActor(img);
    popup.addActor(lbl);/*  ww w .java2  s  . co  m*/
    lbl.setPosition(img.getRight(), (img.getHeight() - lbl.getHeight()) * 0.5f);
    popup.setSize(lbl.getRight(), img.getTop());
    popup.setPosition((stage.getWidth() - popup.getWidth()) * 0.5f,
            (stage.getHeight() - popup.getHeight()) * 0.5f);
    popup.setColor(popup.getColor().r, popup.getColor().g, popup.getColor().b, 0);
    stage.addActor(popup);
    popup.addAction(Actions.sequence(Actions.fadeIn(0.5f), Actions.delay(duration), Actions.fadeOut(0.5f)));
    return popup;
}

From source file:com.ahsgaming.valleyofbones.screens.LevelScreen.java

License:Apache License

public Group popupMessage(String text, String icon, float duration) {
    Gdx.app.log(LOG, "Popup message!");
    Group popup = new Group();
    Label lbl = new Label(text, getSkin(), "medium");
    lbl.setFontScale(VOBGame.SCALE);/*from   w  w  w . ja  v  a  2 s . c  om*/
    Image img = new Image(VOBGame.instance.getTextureManager().getSpriteFromAtlas("assets", icon));
    popup.addActor(img);
    popup.addActor(lbl);
    lbl.setPosition(img.getRight(), (img.getHeight() - lbl.getHeight()) * 0.5f);
    popup.setSize(lbl.getX() + lbl.getWidth() * lbl.getFontScaleX(), img.getTop());
    popup.setPosition((stage.getWidth() - popup.getWidth()) * 0.5f,
            turnPanel.getY() - popup.getHeight() - 20 * VOBGame.SCALE);
    popup.setColor(popup.getColor().r, popup.getColor().g, popup.getColor().b, 0);
    stage.addActor(popup);
    popup.addAction(Actions.sequence(Actions.fadeIn(0.5f), Actions.delay(duration), Actions.fadeOut(0.5f),
            Actions.removeActor()));
    return popup;
}

From source file:com.badlogic.gdx.tests.lw.StageTestLW.java

License:Apache License

private void fillGroup(Group group, Texture texture) {
    float advance = 32 + SPACING;
    for (int y = 0; y < NUM_SPRITES * advance; y += advance)
        for (int x = 0; x < NUM_SPRITES * advance; x += advance) {
            Image img = new Image(group.name + "-sprite" + x * y, texture);
            img.x = x;//  w ww.j a  va2s  .  c  om
            img.y = y;
            img.width = 32;
            img.height = 32;
            group.addActor(img);
            images.add(img);
        }
}

From source file:com.blastedstudios.gdxworld.util.ui.Scene2DUtils.java

License:Apache License

/** Adds the given Actor to the given Group at the coordinates relative to the Stage.
 *  @param actor the Actor to add to the given Group
 *  @param newParent the Group to add the given Actor to */
public static void addAtStageCoordinates(Actor actor, Group newParent) {
    tmp.set(positionInStageCoordinates(actor));
    newParent.stageToLocalCoordinates(tmp);
    newParent.addActor(actor);
    actor.setPosition(tmp.x, tmp.y);// w w w  . j  a  v  a  2s  . c o  m
}

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

public void init() {

    setBackgroundColor(StartTrackApp.ColorPallete.BACK);
    setWidth(Gdx.graphics.getWidth());/*from   w  ww.  j a va  2  s .  c om*/

    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.gmail.emersonmx.tictactoe.GameScreen.java

License:Open Source License

private Actor createHash() {
    Group group = new Group();
    group.setName("hash");

    GridPoint2[] layout = new GridPoint2[] { new GridPoint2(179, 401), new GridPoint2(240, 462),
            new GridPoint2(301, 401), new GridPoint2(240, 340) };

    Sprite sprite = null;//from w w  w  .j  a  v a 2s.co  m
    GridPoint2 point = null;
    for (int i = 0; i < layout.length; ++i) {
        point = layout[i];

        sprite = ttt.atlas.createSprite("hash_line");
        sprite.setCenter(point.x, point.y);
        if (i % 2 != 0) {
            sprite.rotate(90);
        }

        group.addActor(new SpriteActor("hash_line_" + i, sprite));
    }

    return group;
}

From source file:com.gmail.emersonmx.tictactoe.GameScreen.java

License:Open Source License

private Actor createPlayerMarks(String name, Color color) {
    Group group = new Group();
    group.setName(name);/*from ww w  .j a  v a 2 s. c o m*/

    GridPoint2[] layout = createPlayerMarkLayout();
    Array<Rectangle> rectangles = createPlayerMarkRectangles();

    GridPoint2 point;
    Rectangle rectangle;
    for (int i = 0; i < layout.length; i++) {
        point = layout[i];
        rectangle = rectangles.get(i);

        Sprite[] sprites = createMarks();
        for (Sprite sprite : sprites) {
            sprite.setCenter(point.x, point.y);
            sprite.setColor(color);
        }

        Array<Sprite> array = new Array<Sprite>(sprites);
        SpritesActor actor = new SpritesActor(name + "_" + i, array);
        actor.setIndex(SpritesActor.HIDDEN);
        actor.setTouchable(Touchable.enabled);
        actor.setBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
        actor.setUserObject(i);
        actor.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                SpritesActor actor = (SpritesActor) event.getTarget();
                Integer mark = (Integer) actor.getUserObject();
                ttt.mark(mark);
                System.out.println("Mark " + mark + " touched");
            }

        });

        group.addActor(actor);
    }

    return group;
}

From source file:com.gmail.emersonmx.tictactoe.GameScreen.java

License:Open Source License

private Actor createScoreSeparators() {
    Group group = new Group();
    group.setName("score_separators");

    GridPoint2[] layout = new GridPoint2[] { new GridPoint2(192, 87), new GridPoint2(288, 87) };

    GridPoint2 point = null;/*from w  ww  .  ja  va  2  s. c  o  m*/
    Sprite sprite = null;
    for (int i = 0; i < layout.length; ++i) {
        point = layout[i];

        sprite = ttt.atlas.createSprite("score_separator");
        sprite.setCenter(point.x, point.y);
        group.addActor(new SpriteActor("score_separator_" + i, sprite));
    }

    return group;
}