com.badlogic.gdx.scenes.scene2d.Actor.draw()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(109)

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

Actor.draw介绍

[英]Draws the actor. The batch is configured to draw in the parent's coordinate system. Batch#draw(com.badlogic.gdx.graphics.g2d.TextureRegion,float,float,float,float,float,float,float,float,float) is convenient to draw a rotated and scaled TextureRegion. Batch#begin() has already been called on the batch. If Batch#end() is called to draw without the batch then Batch#begin() must be called before the method returns.

The default implementation does nothing.
[中]吸引演员。批次配置为在父对象的坐标系中绘制。Batch#draw(com.badlogic.gdx.graphics.g2d.TextureRegion,float,float,float,float,float,float,float,float)可以方便地绘制旋转和缩放的TextureRegion。批处理#begin()已在批处理上调用。如果调用Batch#end()来绘制而不使用Batch,则必须在方法返回之前调用Batch#begin()。
默认实现不执行任何操作。

代码示例

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

float cx = child.x, cy = child.y;
if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom)
  child.draw(batch, parentAlpha);
  child.x = cx + offsetX;
  child.y = cy + offsetY;
  child.draw(batch, parentAlpha);
  child.x = cx;
  child.y = cy;
Actor child = actors[i];
if (!child.isVisible()) continue;
child.draw(batch, parentAlpha);
child.x = cx + offsetX;
child.y = cy + offsetY;
child.draw(batch, parentAlpha);
child.x = cx;
child.y = cy;

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

float cx = child.x, cy = child.y;
if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom)
  child.draw(batch, parentAlpha);
  child.x = cx + offsetX;
  child.y = cy + offsetY;
  child.draw(batch, parentAlpha);
  child.x = cx;
  child.y = cy;
Actor child = actors[i];
if (!child.isVisible()) continue;
child.draw(batch, parentAlpha);
child.x = cx + offsetX;
child.y = cy + offsetY;
child.draw(batch, parentAlpha);
child.x = cx;
child.y = cy;

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

@Override
public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  float alpha = color.a * parentAlpha;
  applyTransform(batch, computeTransform());
  if (firstWidget != null && firstWidget.isVisible()) {
    batch.flush();
    getStage().calculateScissors(firstWidgetBounds, tempScissors);
    if (ScissorStack.pushScissors(tempScissors)) {
      firstWidget.draw(batch, alpha);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  if (secondWidget != null && secondWidget.isVisible()) {
    batch.flush();
    getStage().calculateScissors(secondWidgetBounds, tempScissors);
    if (ScissorStack.pushScissors(tempScissors)) {
      secondWidget.draw(batch, alpha);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  batch.setColor(color.r, color.g, color.b, alpha);
  style.handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
  resetTransform(batch);
}

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

@Override
public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  float alpha = color.a * parentAlpha;
  applyTransform(batch, computeTransform());
  if (firstWidget != null && firstWidget.isVisible()) {
    batch.flush();
    getStage().calculateScissors(firstWidgetBounds, tempScissors);
    if (ScissorStack.pushScissors(tempScissors)) {
      firstWidget.draw(batch, alpha);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  if (secondWidget != null && secondWidget.isVisible()) {
    batch.flush();
    getStage().calculateScissors(secondWidgetBounds, tempScissors);
    if (ScissorStack.pushScissors(tempScissors)) {
      secondWidget.draw(batch, alpha);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  batch.setColor(color.r, color.g, color.b, alpha);
  style.handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
  resetTransform(batch);
}

代码示例来源:origin: dingjibang/GDX-RPG

public TypedGdxQuery<T> draw(Batch batch, float pf){
  t.draw(batch,pf);
  return this;
}

代码示例来源:origin: dingjibang/GDX-RPG

public GdxQuery draw(Batch batch,float pf){
  for(Actor actor:list())
    actor.draw(batch,pf);
  return this;
}

代码示例来源:origin: danialgoodwin/dev

@Override
public void draw(Batch batch, float parentAlpha) {
  super.draw(batch, parentAlpha);
  batch.draw(textureRegion, textureRegionBounds1.x, textureRegionBounds1.y, Constants.APP_WIDTH,
      Constants.APP_HEIGHT);
  batch.draw(textureRegion, textureRegionBounds2.x, textureRegionBounds2.y, Constants.APP_WIDTH,
      Constants.APP_HEIGHT);
}

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

/**
 * Draws one AnimatedEntity, specifically the Actor it contains. Batch must be between start() and end()
 * @param batch Must have start() called already but not stop() yet during this frame.
 * @param parentAlpha This can be assumed to be 1.0f if you don't know it
 * @param ac The Actor to draw; the position to draw ac is modified and reset based on some fields of this object
 */
public void drawActor(Batch batch, float parentAlpha, Actor ac)
{
  float prevX = ac.getX(), prevY = ac.getY();
  ac.setPosition(prevX - gridOffsetX * cellWidth, prevY + gridOffsetY * cellHeight);
  ac.draw(batch, parentAlpha);
  ac.setPosition(prevX, prevY);
}

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

/**
 * Draws one AnimatedEntity, specifically the Actor it contains. Batch must be between start() and end()
 * @param batch Must have start() called already but not stop() yet during this frame.
 * @param parentAlpha This can be assumed to be 1.0f if you don't know it
 * @param ac The Actor to draw; the position to draw ac is modified and reset based on some fields of this object
 */
public void drawActor(Batch batch, float parentAlpha, Actor ac)
{
  float prevX = ac.getX(), prevY = ac.getY();
  ac.setPosition(prevX - gridOffsetX * cellWidth, prevY + gridOffsetY * cellHeight);
  ac.draw(batch, parentAlpha);
  ac.setPosition(prevX, prevY);
}

代码示例来源:origin: LonamiWebs/Klooni1010

@Override
public void draw(Batch batch, float parentAlpha) {
  super.draw(batch, parentAlpha);
  final float x = getX(), y = getY();
  nameLabel.setBounds(x + nameBounds.x, y + nameBounds.y, nameBounds.width, nameBounds.height);
  nameLabel.draw(batch, parentAlpha);
  priceLabel.setBounds(x + priceBounds.x, y + priceBounds.y, priceBounds.width, priceBounds.height);
  priceLabel.draw(batch, parentAlpha);
}

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

@Override
  public void draw (final Batch batch, final float parentAlpha) {
    if (actor != null) {
      LAST_POSITION.set(actor.getX(), actor.getY());
      actor.setPosition(getX(), getY());
      actor.draw(batch, getColor().a * parentAlpha);
      actor.setPosition(LAST_POSITION.x, LAST_POSITION.y);
    }
  }
}

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

public void drawBackground() {
  if (bgList.size() != 0) {
    Batch batch = getBatch();
    batch.begin();
    batch.setColor(1, 1, 1, 1);
    for (Actor bg : bgList) {
      float prefx = bg.getX();
      float prefy = bg.getY();
      bg.setPosition(getWidth() / 2, getHeight() / 2, Align.center);
      bg.draw(batch, getRoot().getColor().a);
      bg.setPosition(prefx, prefy);
    }
    batch.end();
  }
}

代码示例来源:origin: jsjolund/GdxDemo3D

@Override
public void draw() {
  batch.begin();
  for (Actor actor : getActors()) {
    if (actor.isVisible()) {
      actor.draw(batch, 1);
    }
  }
  batch.end();
  if (DebugViewSettings.drawUIDebug) {
    shapeRenderer.begin();
    rootTable.drawDebug(shapeRenderer);
    shapeRenderer.end();
  }
  cameraController.update();
}

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

@Override
public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  applyTransform(batch, computeTransform());
  // Matrix4 transform = batch.getTransformMatrix();
  if (firstWidget != null) {
    getStage().calculateScissors(firstWidgetBounds, firstScissors);
    if (ScissorStack.pushScissors(firstScissors)) {
      if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  if (secondWidget != null) {
    getStage().calculateScissors(secondWidgetBounds, secondScissors);
    if (ScissorStack.pushScissors(secondScissors)) {
      if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  Drawable handle = style.handle;
  if (mouseOnHandle && isTouchable() && style.handleOver != null) handle = style.handleOver;
  batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
  handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
  resetTransform(batch);
}

代码示例来源:origin: mbrlabs/Mundus

@Override
public void draw(Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  applyTransform(batch, computeTransform());
  // Matrix4 transform = batch.getTransformMatrix();
  if (firstWidget != null) {
    getStage().calculateScissors(firstWidgetBounds, firstScissors);
    if (ScissorStack.pushScissors(firstScissors)) {
      if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  if (secondWidget != null) {
    getStage().calculateScissors(secondWidgetBounds, secondScissors);
    if (ScissorStack.pushScissors(secondScissors)) {
      if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  Drawable handle = style.handle;
  if (mouseOnHandle && isTouchable() && style.handleOver != null) handle = style.handleOver;
  batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
  handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
  resetTransform(batch);
}

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

@Override
public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  float alpha = color.a * parentAlpha;
  applyTransform(batch, computeTransform());
  if (firstWidget != null && firstWidget.isVisible()) {
    batch.flush();
    getStage().calculateScissors(firstWidgetBounds, tempScissors);
    if (ScissorStack.pushScissors(tempScissors)) {
      firstWidget.draw(batch, alpha);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  if (secondWidget != null && secondWidget.isVisible()) {
    batch.flush();
    getStage().calculateScissors(secondWidgetBounds, tempScissors);
    if (ScissorStack.pushScissors(tempScissors)) {
      secondWidget.draw(batch, alpha);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  batch.setColor(color.r, color.g, color.b, alpha);
  style.handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
  resetTransform(batch);
}

代码示例来源:origin: moribitotech/MTX

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
  super.draw(batch, parentAlpha);
  // For fade out/in effect
  batch.setColor(this.getColor().r, this.getColor().g, this.getColor().b,
      parentAlpha * this.getColor().a);
  // DRAW TEXTURE REGION (Draw only if set active and not null)
  // ##################################################################
  if (isTextureRegionActive && textureRegion != null) {
    // Draw it due to actors' settings
    batch.draw(textureRegion, getX(), getY(), getOriginX(),
        getOriginY(), getWidth(), getHeight(), getScaleX(),
        getScaleY(), getRotation());
  }
}

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

@Override
public void draw(Batch batch, float parentAlpha) {
  super.draw(batch, parentAlpha);
  if (region == null || !isVisible()) {
    return;
  }
  // 备份 batch 原本的 Color
  Color tempBatchColor = batch.getColor();
  // 获取演员的 Color
  Color color = getColor();
  // 将演员的 Color 结合 parentAlpha 设置到 batch
  batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
  // 结合演员的属性绘制表示演员的纹理区域
  batch.draw(
      region,
      getX(), getY(),
      getOriginX(), getOriginY(),
      getWidth(), getHeight(),
      getScaleX(), getScaleY(),
      getRotation()
  );
  // 还原 batch 原本的 Color
  batch.setColor(tempBatchColor);
}

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

@Override
public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  applyTransform(batch, computeTransform());
  SnapshotArray<Actor> actors = getChildren();
  for (int i = 0; i < actors.size; i++) {
    Actor actor = actors.get(i);
    Rectangle bounds = widgetBounds.get(i);
    Rectangle scissor = scissors.get(i);
    getStage().calculateScissors(bounds, scissor);
    if (ScissorStack.pushScissors(scissor)) {
      if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
  Drawable handle = style.handle;
  Drawable handleOver = style.handle;
  if (isTouchable() && style.handleOver != null) handleOver = style.handleOver;
  for (Rectangle rect : handleBounds) {
    if (this.handleOver == rect) {
      handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height);
    } else {
      handle.draw(batch, rect.x, rect.y, rect.width, rect.height);
    }
  }
  resetTransform(batch);
}

代码示例来源:origin: mbrlabs/Mundus

@Override
public void draw(Batch batch, float parentAlpha) {
  validate();
  Color color = getColor();
  applyTransform(batch, computeTransform());
  SnapshotArray<Actor> actors = getChildren();
  for (int i = 0; i < actors.size; i++) {
    Actor actor = actors.get(i);
    Rectangle bounds = widgetBounds.get(i);
    Rectangle scissor = scissors.get(i);
    getStage().calculateScissors(bounds, scissor);
    if (ScissorStack.pushScissors(scissor)) {
      if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a);
      batch.flush();
      ScissorStack.popScissors();
    }
  }
  batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
  Drawable handle = style.handle;
  Drawable handleOver = style.handle;
  if (isTouchable() && style.handleOver != null) handleOver = style.handleOver;
  for (Rectangle rect : handleBounds) {
    if (this.handleOver == rect) {
      handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height);
    } else {
      handle.draw(batch, rect.x, rect.y, rect.width, rect.height);
    }
  }
  resetTransform(batch);
}

相关文章