com.badlogic.gdx.scenes.scene2d.ui.Image类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中com.badlogic.gdx.scenes.scene2d.ui.Image类的一些代码示例,展示了Image类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Image类的具体详情如下:
包路径:com.badlogic.gdx.scenes.scene2d.ui.Image
类名称:Image

Image介绍

[英]Displays a Drawable, scaled various way within the widgets bounds. The preferred size is the min size of the drawable. Only when using a TextureRegionDrawable will the actor's scale, rotation, and origin be used when drawing.
[中]在窗口小部件范围内以各种方式显示可绘制、缩放的窗口小部件。首选尺寸为可拉深件的最小尺寸。只有在使用TextureRegionRavable时,才会在绘制时使用演员的比例、旋转和原点。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  stage = new Stage();
  texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), false);
  texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
  img = new Image(new TextureRegion(texture));
  img.setSize(100, 100);
  img.setOrigin(50, 50);
  img.setPosition(100, 100);
  img2 = new Image(new TextureRegion(texture));
  img2.setSize(100, 100);
  img2.setOrigin(50, 50);
  img2.setPosition(100, 100);
  img3 = new Image(new TextureRegion(texture));
  img3.setSize(100, 100);
  img3.setOrigin(50, 50);
  img3.setPosition(100, 100);
  stage.addActor(img);
  stage.addActor(img2);
  stage.addActor(img3);
  img.addAction(sequence());
  img2.addAction(parallel(sequence(), moveBy(100, 0, 1)));
  img3.addAction(sequence(parallel(moveBy(100, 200, 2)), Actions.run(this)));
}

代码示例来源:origin: libgdx/libgdx

public void layout () {
  if (drawable == null) return;
  float regionWidth = drawable.getMinWidth();
  float regionHeight = drawable.getMinHeight();
  float width = getWidth();
  float height = getHeight();
  Vector2 size = scaling.apply(regionWidth, regionHeight, width, height);
  imageWidth = size.x;
  imageHeight = size.y;
  if ((align & Align.left) != 0)
    imageX = 0;
  else if ((align & Align.right) != 0)
    imageX = (int)(width - imageWidth);
  else
    imageX = (int)(width / 2 - imageWidth / 2);
  if ((align & Align.top) != 0)
    imageY = (int)(height - imageHeight);
  else if ((align & Align.bottom) != 0)
    imageY = 0;
  else
    imageY = (int)(height / 2 - imageHeight / 2);
}

代码示例来源:origin: libgdx/libgdx

/** @param drawable May be null. */
public Image (Drawable drawable, Scaling scaling, int align) {
  setDrawable(drawable);
  this.scaling = scaling;
  this.align = align;
  setSize(getPrefWidth(), getPrefHeight());
}

代码示例来源:origin: libgdx/libgdx

public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
  float x = getX();
  float y = getY();
  float scaleX = getScaleX();
  float scaleY = getScaleY();
  if (drawable instanceof TransformDrawable) {
    float rotation = getRotation();
    if (scaleX != 1 || scaleY != 1 || rotation != 0) {
      ((TransformDrawable)drawable).draw(batch, x + imageX, y + imageY, getOriginX() - imageX, getOriginY() - imageY,
        imageWidth, imageHeight, scaleX, scaleY, rotation);
      return;
    }
  }
  if (drawable != null) drawable.draw(batch, x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
}

代码示例来源:origin: libgdx/libgdx

public void create () {
  stage = new Stage();
  Gdx.input.setInputProcessor(stage);
  texture = new Texture("data/group-debug.png");
  Image image = new Image(texture);
  image.setScaling(Scaling.fit);
  image.setBounds(100, 100, 400, 200);
  stage.addActor(image);
  Image image2 = new Image(texture);
  image2.setScaling(Scaling.fit);
  image.setBounds(100, 100, 400, 200);
  image2.setOrigin(200, 100);
  image2.setScale(0.5f);
  stage.addActor(image2);
}

代码示例来源:origin: SquidPony/SquidLib

/**
 * Creates a Image Actor that should look like the glyph '^' in this font, but will be rotate-able.
 * @param color a Color to tint the '^' with
 * @return the Actor, with no position set.
 */
public Image makeDirectionMarker(Color color) {
  if (!initialized) {
    throw new IllegalStateException("This factory has not yet been initialized!");
  }
  Image im = new Image(dirMarker);
  im.setColor(scc.filter(color));
  im.setSize(actualCellWidth, actualCellHeight + (distanceField ? 1 : 0)); //  - lineHeight / actualCellHeight //+ lineTweak * 1f
  im.setOrigin(1); //center
  return im;
}

代码示例来源:origin: com.lwgame.gdx/core

@Override
public void create() {
  texture = new Texture("badlogic.jpg");
  Image image = new Image(texture);
  image.setPosition((stage.getWidth() - image.getWidth()) / 2, (stage.getHeight() - image.getHeight()) / 2);
  stage.addActor(image);
}

代码示例来源:origin: xietansheng/Game2048ForGDX

bgImage = new Image(getMainGame().getAtlas().findRegion(Res.AtlasNames.GAME_BLANK));
bgImage.setColor(bgColor);
bgImage.setOrigin(0, 0);
bgImage.setScale(getWidth() / bgImage.getWidth(), getHeight() / bgImage.getHeight());
addActor(bgImage);

代码示例来源:origin: Var3D/var3dframe

public UI<Image> getImage(String name, float width, float height, int left, int right, int top, int bottom) {
  Image image = new Image(getNinePatch(name, left, right, top, bottom));
  image.setSize(width, height);
  return getUI(image);
}

代码示例来源:origin: SquidPony/SquidLib

/**
 * Converts a TextureRegion into an Image, or if the argument s is null, creates an Image of a solid block. Can be
 * used for preparing images for animation effects. Ensures the returned Image has the given width and height.
 * @param tr a TextureRegion to make into an Actor, which can be null for a solid block.
 * @param color a Color to tint tr with.
 * @return the Actor, with no position set.
 */
public Actor makeActor(TextureRegion tr, Color color, float width, float height) {
  if (!initialized) {
    throw new IllegalStateException("This factory has not yet been initialized!");
  }
  if (tr == null) {
    Image im = new Image(block);
    im.setColor(scc.filter(color));
    im.setSize(width, height);
    // im.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
    return im;
  } else {
    Image im = new Image(tr);
    im.setColor(scc.filter(color));
    im.setSize(width, height);
    // im.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
    return im;
  }
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

backgroundImage = new Image(atlas.findRegion(backgroundFrame));
foregroundImage = new Image(atlas.findRegion(foregroundFrame));
  this.boundaryHeight = resolutionHelper.getScreenHeight();
  setSize(boundaryWidth, boundaryHeight);
  backgroundImage.setPosition(boundaryWidth / 2 - this.backgroundImage.getWidth() / 2, boundaryHeight / 2 - this.backgroundImage.getHeight() / 2);
  foregroundImage.setPosition(boundaryWidth / 2 - this.foregroundImage.getWidth() / 2, boundaryHeight / 2 - this.foregroundImage.getHeight() / 2);
  if(messageLabel != null) {				
    messageLabel.setPosition(boundaryWidth / 2 - halfOfMessageLabelWidth, boundaryHeight / 2 - halfOfMessageLabelHeight);
  backgroundImage.setSize(boundaryWidth, boundaryHeight);
  foregroundImage.setSize(boundaryWidth, boundaryHeight);
  if(messageLabel != null) {					
    messageLabel.setPosition(backgroundImage.getWidth() / 2 - halfOfMessageLabelWidth, backgroundImage.getHeight() / 2 - halfOfMessageLabelHeight);
foregroundImage.setOrigin(foregroundImage.getWidth() / 2, foregroundImage.getHeight() / 2);
backgroundImage.setOrigin(backgroundImage.getWidth() / 2, backgroundImage.getHeight() / 2);

代码示例来源:origin: xietansheng/Game2048ForGDX

bgImage = new Image(getMainGame().getAtlas().findRegion(Res.AtlasNames.GAME_BLANK));
bgImage.setColor(bgColor);
bgImage.setOrigin(0, 0);
bgImage.setScale(getWidth() / bgImage.getWidth(), getHeight() / bgImage.getHeight());
addActor(bgImage);
helpContentImage = new Image(getMainGame().getAtlas().findRegion(Res.AtlasNames.GAME_HELP_BG));
helpContentImage.setX(getWidth() / 2 - helpContentImage.getWidth() / 2);
helpContentImage.setY(getHeight() - helpContentImage.getHeight());
addActor(helpContentImage);

代码示例来源:origin: libgdx/libgdx

ui = new Stage(new ScreenViewport());
Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
blend.setAlign(Align.center);
blend.setScaling(Scaling.none);
blend.addListener(new InputListener() {
  public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
    if (stage.getBatch().isBlendingEnabled())
blend.setY(ui.getHeight() - 64);
Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
rotate.setAlign(Align.center);
rotate.setScaling(Scaling.none);
rotate.addListener(new InputListener() {
  public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
    rotateSprites = !rotateSprites;
rotate.setPosition(64, blend.getY());
Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
scale.setAlign(Align.center);
scale.setScaling(Scaling.none);
scale.addListener(new InputListener() {
  public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
    scaleSprites = !scaleSprites;
scale.setPosition(128, blend.getY());

代码示例来源:origin: libgdx/libgdx

public ImageButton (ImageButtonStyle style) {
  super(style);
  image = new Image();
  image.setScaling(Scaling.fit);
  add(image);
  setStyle(style);
  setSize(getPrefWidth(), getPrefHeight());
}

代码示例来源:origin: xietansheng/Game2048ForGDX

bgImage = new Image(getMainGame().getAtlas().findRegion(Res.AtlasNames.GAME_BLANK));
bgImage.setColor(bgColor);
bgImage.setOrigin(0, 0);
bgImage.setScaleX(getWidth() / bgImage.getWidth());
addActor(bgImage);
bgImage.setScaleY(getHeight() / bgImage.getHeight());

代码示例来源:origin: libgdx/libgdx

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(new TextureRegion(texture));
      img.setAlign(Align.center);
      img.setScaling(Scaling.none);
      img.setBounds(x, y, 32, 32);
      img.setOrigin(16, 16);
      group.addActor(img);
      sprites.add(img);
    }
}

代码示例来源:origin: libgdx/libgdx

public CheckBox (String text, CheckBoxStyle style) {
  super(text, style);
  clearChildren();
  Label label = getLabel();
  imageCell = add(image = new Image(style.checkboxOff, Scaling.none));
  add(label);
  label.setAlignment(Align.left);
  setSize(getPrefWidth(), getPrefHeight());
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

public ToggleWidget(ToggleWidgetStyle style) {
  this.style = style;
  background = new Image(style.backgroundDrawable);
  addActor(background);
  toggleButton = new Image(style.toggleButtonDrawable);
  addActor(toggleButton);
  float width = background.getWidth();
  float height = Math.max(toggleButton.getHeight(), background.getHeight());
  setWidth(width);
  setHeight(height);
  background.setY((getHeight()-background.getHeight())/2);
  toggleButton.setY((getHeight()-toggleButton.getHeight())/2);
  addListener(new ToggleWidgetClickListener());
  maxButtonX = getWidth() - toggleButton.getWidth();
  minButtonX = 0;
  minButtonX += style.toggleButtonPadding/2;
  maxButtonX -= style.toggleButtonPadding/2;
  isLeft = true;
  toggleButton.setX(minButtonX);
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

private void prepareBackgroundImage(AssetsInterface assets, float sizeMult) {
  TextureAtlas atlas = assets.getTextureAtlas(this.atlasName);
  this.backgroundImage = new Image(atlas.findRegion(this.backgroundImageFrame));
  this.backgroundImage.setWidth(this.backgroundImage.getWidth() * sizeMult);
  this.backgroundImage.setHeight(this.backgroundImage.getHeight() * sizeMult);
}

代码示例来源:origin: kotcrab/vis-ui

public void draw (Batch batch, Image parent) {
    ShaderProgram originalShader = batch.getShader();
    batch.setShader(gridShader);
    gridShader.setUniformf("u_width", parent.getWidth());
    gridShader.setUniformf("u_height", parent.getHeight());
    gridShader.setUniformf("u_gridSize", gridSize);
    batch.draw(whiteTexture, parent.getX() + parent.getImageX(), parent.getY() + parent.getImageY(),
        parent.getImageWidth() * parent.getScaleX(), parent.getImageHeight() * parent.getScaleY());
    batch.setShader(originalShader);
  }
}

相关文章