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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Image#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: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopRightCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setRotation(-90);
    image.setPosition(x * CELL_SIZE, (y + 1) * CELL_SIZE);
    return image;
}
 
Example 2
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public void showSelection(Object key, Array<Grid2D.Coordinate> coordinates, String selectionName) {
    if (selectionMap.containsKey(key))
        throw new IllegalStateException("there is already associated selection with key " + key);
    Drawable drawable = Config.skin.getDrawable(selectionName);
    Array<Image> selections = new Array<Image>();
    for (Grid2D.Coordinate coordinate : coordinates) {
        Image image = new Image(drawable);
        blink(image, 0.2f, 1f);
        image.setPosition(coordinate.x() * CELL_SIZE, coordinate.y() * ViewController.CELL_SIZE);
        selectionLayer.addActor(image);
        selections.add(image);
    }
    selectionMap.put(key, selections);
}
 
Example 3
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopOutline(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-outline").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    image.setRotation(90);
    layer.addActor(image);
    image.setPosition((x + 1) * CELL_SIZE, (y + 1) * CELL_SIZE - image.getWidth());
    return image;
}
 
Example 4
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addLeftOutline(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-outline").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    image.setRotation(180);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE + image.getWidth(), (y + 1) * CELL_SIZE);
    return image;
}
 
Example 5
Source File: CCPanel.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    Table table = new Table();

    Size size = widget.getSize();
    if (widget.getComboBoxIndex() == 0) { // 无颜色

    } else if (widget.getComboBoxIndex() == 1 && widget.getBackColorAlpha() != 0) {// 单色
        Pixmap pixmap = new Pixmap((int) size.getX(), (int) size.getY(),
            Format.RGBA8888);

        pixmap.setColor(editor.getColor(widget.getSingleColor(),
            widget.getBackColorAlpha()));

        pixmap.fill();

        Drawable d = new TextureRegionDrawable(new TextureRegion(
            new Texture(pixmap)));
        table.setBackground(d);
        pixmap.dispose();
    }

    if (widget.getFileData() != null) {// Panel的图片并不是拉伸平铺的!!.但是这里修改为填充
        Drawable tr = editor.findDrawable(widget, widget.getFileData());
        if (tr != null) {
            Image bg = new Image(tr);
            bg.setPosition((size.getX() - bg.getWidth()) / 2,
                (size.getY() - bg.getHeight()) / 2);
            // bg.setFillParent(true);
            bg.setTouchable(Touchable.disabled);

            table.addActor(bg);
        }
    }

    table.setClip(widget.isClipAble());

    return table;
}
 
Example 6
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addOverHang(int x, int y, String name, String type, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-overhang-" + type).random();
    if (region == null) {
        region = Config.findRegions("tile/" + name + "-overhang").random();
        if (region == null)
            return null;
    }
    Image image = new Image(region);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, (y + 1) * CELL_SIZE - image.getHeight());
    return image;
}
 
Example 7
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addBottomRightCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setRotation(180);
    image.setPosition((x + 1) * CELL_SIZE, (y + 1) * CELL_SIZE);
    return image;
}
 
Example 8
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addBottomLeftCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setRotation(90);
    image.setPosition((x + 1) * CELL_SIZE, (y) * CELL_SIZE);
    return image;
}
 
Example 9
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopLeftCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, y * CELL_SIZE);
    return image;
}
 
Example 10
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private void addBackgroundObject(boolean anywhere) {
    final Image image = new Image(backgroundDrawables.random());
    backgroundLayer.addActor(image);


    float scale = 0.5f * MathUtils.random(1, 2);
    image.setSize(image.getPrefWidth() * scale, image.getPrefHeight() * scale);
    image.setRotation(MathUtils.random(0, 1) * 180);
    image.getColor().a = MathUtils.random(0.1f, 0.3f);

    float w = Math.max(world.stage.getWidth(), root.getWidth() + ViewScroller.LEFT + ViewScroller.RIGHT);
    float h = Math.max(world.stage.getHeight(), root.getHeight() + ViewScroller.TOP + ViewScroller.BOTTOM);

    if (anywhere)
        image.setPosition(-root.getX() + w * MathUtils.random(), -root.getY() + h * MathUtils.random());
    else
        image.setPosition(-root.getX() - image.getWidth(), -root.getY() + h * MathUtils.random());

    image.addAction(Actions.sequence(
        Actions.moveBy(w + image.getWidth() - image.getX(), 0, 15 + MathUtils.random(6)),
        Actions.run(new Runnable() {
            @Override public void run() {
                image.remove();
                addBackgroundObject(false);
            }
        })
    ));
}
 
Example 11
Source File: BeamVisualizer.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public IFuture<Void> visualize(ITargetOwner result) {
    final Future<Void> future = new Future<Void>();
    SoundManager.instance.playSoundIfExists(soundName);
    Image image = new Image(Config.skin, "effect-luck-image");
    image.setColor(color);
    image.setScale(0, 0);
    image.setOrigin(image.getWidth() / 2, image.getHeight() / 2);
    image.setPosition(
        result.getTarget().getX() * ViewController.CELL_SIZE + (ViewController.CELL_SIZE - image.getWidth()) * 0.5f,
        result.getTarget().getY() * ViewController.CELL_SIZE + (ViewController.CELL_SIZE - image.getHeight()) * 0.5f + 6
    );
    visualizer.viewController.effectLayer.addActor(image);
    image.addAction(
        Actions.sequence(
            Actions.parallel(
                Actions.scaleTo(0.75f, 0.75f, 0.5f, Interpolation.sine),
                Actions.rotateBy(135, 0.5f)
            ),
            Actions.parallel(
                Actions.scaleTo(0, 0, 0.5f, Interpolation.sine),
                Actions.rotateBy(135, 0.5f)
            ),
            Actions.run(future),
            Actions.removeActor()
        )
    );
    return future;
}
 
Example 12
Source File: CommonShotVisualizer.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public IFuture<Void> visualize(final T result) {
    final Future<Void> future = Future.make();
    final WorldObjectView actorView = visualizer.viewController.getView(result.getActor());
    WorldObjectView targetView = visualizer.viewController.getView(result.getTarget());
    visualizer.viewController.world.dispatcher.dispatch(ResultVisualizer.VISUALIZE_ATTACK, result.getActor());
    Vector2 direction = tmp
        .set(result.getTarget().getX(), result.getTarget().getY())
        .sub(result.getActor().getX(), result.getActor().getY());

    float dx = targetView.getX() - actorView.getX();
    float dy = targetView.getY() - actorView.getY();
    visualizer.viewController.scroller.centerOn(result.getTarget());

    final Image arrow = new Image(Config.skin,"animation/" + result.getAbility().name + "-shot");
    arrow.setPosition(actorView.getX(), actorView.getY());
    visualizer.viewController.effectLayer.addActor(arrow);
    arrow.setOrigin(13, 14);
    arrow.setRotation(direction.angle() - 45);
    arrow.addAction(Actions.sequence(
        Actions.moveBy(dx, dy, tmp.set(dx, dy).len() * 0.002f),
        Actions.run(new Runnable() {
            @Override public void run() {
                SoundManager.instance.playSoundIfExists(result.getAbility().soundName);
                arrow.remove();
                future.happen();
            }
        })
    ));
    return future;
}
 
Example 13
Source File: Splash.java    From Skyland with MIT License 5 votes vote down vote up
@Override
public void show() {
    queueAssets();

    splashImage = new Image(new Texture(Gdx.files.internal(Textures.TEXTURE_TOXSICK_LOGO)));
    splashImage.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, Align.center);
    Skyland.STAGE.addActor(splashImage);

    addSplashAnimation();
}
 
Example 14
Source File: DieNet.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private void highlight(IntArray indices) {
    for (int i = 0; i < indices.size; i++) {
        Vector2 pos = iconPositions[indices.get(i)];
        Image image = new Image(Config.skin, "ui/dice-window/net-selection-selected");
        image.setPosition(pos.x - 2, pos.y - 2);
        addActor(image);
        image.toBack();
        image.getColor().a = 0f;
        blink(image);
        highlights.add(image);
    }
}
 
Example 15
Source File: PlayerBattleHUD.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void createTileHoverParticle() {
	Utility.loadTextureAsset(Utility.ON_TILE_HOVER_FILE_PATH);
	final TextureRegion tr = new TextureRegion(Utility.getTextureAsset(Utility.ON_TILE_HOVER_FILE_PATH));
	final TextureRegionDrawable trd = new TextureRegionDrawable(tr);
	onTileHover = new Image(trd);
	onTileHover.setPosition(-1, -1);

	stage.addActor(onTileHover);
}
 
Example 16
Source File: ArrowForceClick.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
@Override public void start(final Callback callback) {
    init();
    final Actor target = getTargetActor();
    final Image arrow = new Image(getArrowDrawable());
    final Table message = getMessageTable();
    final Stage stage = target.getStage();
    ArrowDirection direction = getDirection();
    if (stage == null)
        throw new IllegalStateException("target is not on stage");
    addListener(stage, target, arrow, message, callback);
    stage.addActor(arrow);
    stage.addActor(message);
    Vector2 screenPosition = target.localToStageCoordinates(new Vector2());
    switch (direction) {
        case left:
            arrow.setPosition(
                screenPosition.x - arrow.getPrefWidth() - getArrowOffset(),
                screenPosition.y + target.getHeight() / 2f - arrow.getPrefHeight() / 2f
            );
            message.setSize(arrow.getX() - getArrowOffset(), stage.getHeight());
            break;
        case right:
            arrow.setPosition(
                screenPosition.x + target.getWidth() + getArrowOffset(),
                screenPosition.y + target.getHeight() / 2f - arrow.getPrefHeight() / 2f
            );
            message.setSize(stage.getWidth() - arrow.getX() - arrow.getPrefWidth() - getArrowOffset(), stage.getHeight());
            message.setX(arrow.getX() + arrow.getPrefWidth() + getArrowOffset());
            break;
        case top:
            arrow.setPosition(
                screenPosition.x + target.getWidth() / 2f - arrow.getPrefWidth() / 2f,
                screenPosition.y + target.getHeight() + getArrowOffset()
            );
            message.setSize(stage.getWidth(), stage.getHeight() - arrow.getX() - arrow.getPrefHeight() - getArrowOffset());
            message.setY(arrow.getY() + arrow.getPrefHeight() + getArrowOffset());
            break;
        case bottom:
            arrow.setPosition(
                screenPosition.x + target.getWidth() / 2f - arrow.getPrefWidth() / 2f,
                screenPosition.y - arrow.getPrefHeight() - getArrowOffset()
            );
            message.setSize(stage.getWidth(), arrow.getY() - getArrowOffset());
            break;
        default:
            throw new IllegalStateException("unknown direction: " + direction);
    }

}
 
Example 17
Source File: IntroState.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void init() {
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    textureImage = new Texture("logo-image.png");
    textureText = new Texture("logo-text.png");

    final Image image = new Image(textureImage);
    image.setPosition(stage.getWidth() / 2 - image.getWidth() / 2, stage.getHeight() / 2 - image.getHeight() / 2);

    final Image text = new Image(textureText);
    text.setPosition(image.getX(), image.getY());

    stage.addActor(image);
    stage.addActor(text);
    image.getColor().a = 0;
    text.getColor().a = 0;

    image.addAction(Actions.sequence(
        Actions.alpha(1, 0.3f),
        Actions.run(new Runnable() {
            @Override public void run() {
                text.addAction(
                    Actions.sequence(
                        Actions.alpha(1, 0.3f),
                        Actions.delay(1.5f),
                        Actions.run(new Runnable() {
                            @Override public void run() {
                                image.addAction(Actions.alpha(0, 0.3f));
                                text.addAction(Actions.sequence(
                                    Actions.alpha(0, 0.3f),
                                    Actions.run(new Runnable() {
                                        @Override public void run() {
                                            callback.onEnded();
                                        }
                                    })
                                ));
                            }
                        })
                    )
                );
            }
        })
    ));
}
 
Example 18
Source File: Hud.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
public Hud(SpriteBatch batch, float width, float height) {
    this.batch = batch;

    AssetManager assetManager = GameManager.getInstance().getAssetManager();
    textureAtlas = assetManager.get("img/actors.pack", TextureAtlas.class);
    bombSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Bomb"), 0, 0, 16, 16));
    bombSprite.setBounds(15.0f, 11.5f, 1, 1);

    Pixmap pixmap = new Pixmap(5, 15, Pixmap.Format.RGBA8888);
    pixmap.setColor(240.0f / 255.0f, 128 / 255.0f, 0, 1.0f);
    pixmap.fill();

    bgTexture = new Texture(pixmap);

    pixmap.setColor(1, 1, 1, 1);
    pixmap.fill();
    bombTimerTexture = new Texture(pixmap);
    pixmap.dispose();

    bombTimerSprite = new Sprite(bombTimerTexture);
    bombTimerSprite.setBounds(16f, 12.5f, 3.0f, 0.2f);

    TextureRegion itemTextureRegion = textureAtlas.findRegion("Items");
    powerSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 1, 0, 16, 16));
    powerSprite.setBounds(leftAlignment, 9.0f, 1, 1);

    speedSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 2, 0, 16, 16));
    speedSprite.setBounds(leftAlignment, 8.0f, 1, 1);

    kickSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 3, 0, 16, 16));
    kickSprite.setBounds(leftAlignment, 7.0f, 1, 1);

    remoteSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 4, 0, 16, 16));
    remoteSprite.setBounds(leftAlignment, 6.0f, 1, 1);

    Array<TextureRegion> keyFrames = new Array<TextureRegion>();
    for (int i = 0; i < 5; i++) {
        keyFrames.add(new TextureRegion(textureAtlas.findRegion("Bomberman_big"), 32 * i, 0, 32, 48));
    }
    bigBombermanAnimation = new Animation(0.2f, keyFrames, Animation.PlayMode.LOOP_PINGPONG);
    bigBombermanSprite = new Sprite(bigBombermanAnimation.getKeyFrame(0));
    bigBombermanSprite.setBounds(17.5f, 0.5f, 2f, 3f);
    stateTime = 0;

    FitViewport viewport = new FitViewport(width * SCALE, height * SCALE);
    stage = new Stage(viewport, batch);
    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
    fpsLabel = new Label("FPS:", labelStyle);
    fpsLabel.setFontScale(0.3f);
    fpsLabel.setPosition(16 * SCALE, -0.8f * SCALE);
    fpsLabel.setVisible(showFPS);
    
    levelLabel = new Label("Level", labelStyle);
    levelLabel.setPosition(15.5f * SCALE, 3 * SCALE);
    levelLabel.setFontScale(0.4f);

    playerLivesLabel = new Label("" + GameManager.playerLives, labelStyle);
    playerLivesLabel.setFontScale(0.5f);
    playerLivesLabel.setPosition(16.8f * SCALE, 12.8f * SCALE);

    Image bombermanImage = new Image(new TextureRegion(textureAtlas.findRegion("Items"), 16 * 5, 0, 16, 16));
    bombermanImage.setPosition(leftAlignment * SCALE, 13.5f * SCALE);

    xLabel = new Label("X", labelStyle);
    xLabel.setFontScale(0.4f);
    xLabel.setPosition(16.8f * SCALE, 6.3f * SCALE);

    zLabel = new Label("Z", labelStyle);
    zLabel.setFontScale(0.4f);
    zLabel.setPosition(16.8f * SCALE, 5.3f * SCALE);

    stage.addActor(fpsLabel);
    stage.addActor(levelLabel);
    stage.addActor(playerLivesLabel);
    stage.addActor(bombermanImage);
    stage.addActor(xLabel);
    stage.addActor(zLabel);
    
    stringBuilder = new StringBuilder();
    
}
 
Example 19
Source File: DialogScreen.java    From Unlucky with MIT License 4 votes vote down vote up
public DialogScreen(GameScreen gameScreen, TileMap tileMap, Player player, final ResourceManager rm) {
    super(gameScreen, tileMap, player, rm);

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(350 / 2, 52 / 2);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}
 
Example 20
Source File: BattleEventHandler.java    From Unlucky with MIT License 4 votes vote down vote up
public BattleEventHandler(GameScreen gameScreen, TileMap tileMap, Player player, Battle battle,
                          BattleUIHandler uiHandler, Stage stage, final ResourceManager rm) {
    super(gameScreen, tileMap, player, battle, uiHandler, rm);

    this.stage = stage;

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(175, 26);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleBattleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}