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

x33g5p2x  于2022-01-20 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(136)

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

Group介绍

[英]2D scene graph node that may contain other actors.

Actors have a z-order equal to the order they were inserted into the group. Actors inserted later will be drawn on top of actors added earlier. Touch events that hit more than one actor are distributed to topmost actors first.
[中]可能包含其他角色的2D场景图节点。
演员的z顺序等于他们被插入组中的顺序。稍后插入的参与者将在先前添加的参与者之上绘制。触碰多个演员的触碰事件首先分发给最顶尖的演员。

代码示例

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

private void focusChanged (FocusEvent event) {
    Stage stage = getStage();
    if (isModal && stage != null && stage.getRoot().getChildren().size > 0
      && stage.getRoot().getChildren().peek() == Dialog.this) { // Dialog is top most actor.
      Actor newFocusedActor = event.getRelatedActor();
      if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this)
        && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus)))
        event.cancel();
    }
  }
};

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

Group group = new Group();
group.setX((float)Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
group.setY((float)Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
group.setOrigin(loc, loc);
sprites.add(shapeActor);
Group shapeGroup = new Group();
shapeGroup.setBounds(300, 300, 300, 300);
shapeGroup.setOrigin(50, 75);
shapeGroup.setTouchable(Touchable.childrenOnly);
shapeGroup.addActor(shapeActor);
stage.addActor(shapeGroup);

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

/** If this method is overridden, the super method or {@link #validate()} should be called to ensure the widget group is laid
   * out. */
  public void draw (Batch batch, float parentAlpha) {
    validate();
    super.draw(batch, parentAlpha);
  }
}

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

/** Creates a stage with the specified viewport and batch. This can be used to avoid creating a new batch (which can be
 * somewhat slow) if multiple stages are used during an application's life time.
 * @param batch Will not be disposed if {@link #dispose()} is called, handle disposal yourself. */
public Stage (Viewport viewport, Batch batch) {
  if (viewport == null) throw new IllegalArgumentException("viewport cannot be null.");
  if (batch == null) throw new IllegalArgumentException("batch cannot be null.");
  this.viewport = viewport;
  this.batch = batch;
  root = new Group();
  root.setStage(this);
  viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
}

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

public void draw () {
  Camera camera = viewport.getCamera();
  camera.update();
  if (!root.isVisible()) return;
  Batch batch = this.batch;
  batch.setProjectionMatrix(camera.combined);
  batch.begin();
  root.draw(batch, 1);
  batch.end();
  if (debug) drawDebug();
}

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

private Group createActorGroup (TextureRegionDrawable bob) {
  Actor main = new DrawableActor(bob);
  main.setPosition(0, 0, Align.center);
  Actor hat = new DrawableActor(bob) {
    @Override
    public void act (float delta) {
      rotateBy(delta * -300);
    }
  };
  hat.setOrigin(Align.center);
  hat.setScale(0.5f);
  hat.setPosition(0, 21, Align.center);
  Group group = new Group() {
    @Override
    public void act (float delta) {
      rotateBy(delta * 120);
      setScale(0.9f + 0.2f * MathUtils.cos(MathUtils.degreesToRadians * getRotation()));
      super.act(delta);
    }
  };
  group.addActor(main);
  group.addActor(hat) ;
  // group.setTransform(false);
  float margin = 35;
  float x = MathUtils.random(margin, stage.getWidth() - margin);
  float y = MathUtils.random(margin, stage.getHeight() - margin);
  group.setPosition(x, y);
  group.setRotation(MathUtils.random(0, 360));
  return group;
}

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

protected Matrix4 computeTransform() {
    Affine2 worldTransform = this.worldTransform;
    Group root = getRoot();
    worldTransform.setToTrnRotScl(root.getX(), root.getY(), 0, root.getScaleX(), root.getScaleY());
    computedTransform.set(worldTransform);
    return computedTransform;
  }
}

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

parentHeight = stage.getHeight();
} else {
  parentWidth = parent.getWidth();
  parentHeight = parent.getHeight();
while (parent != null) {
  if (parent instanceof WidgetGroup) return;
  parent = parent.getParent();

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

stage1.getCamera().position.set(100, 100, 0);
Group group = new Group();
group.setRotation(10);
group.setScale(1.2f);
stage1.addActor(group);
actor.setScale(2f);
actor.addAction(forever(rotateBy(360, 8f)));
group.addActor(actor);
group.debugAll();

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

/** Adds an actor to the root of the stage.
 * @see Group#addActor(Actor) */
public void addActor (Actor actor) {
  root.addActor(actor);
}

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

public void validate () {
  if (!layoutEnabled) return;
  Group parent = getParent();
  if (fillParent && parent != null) {
    float parentWidth, parentHeight;
    Stage stage = getStage();
    if (stage != null && parent == stage.getRoot()) {
      parentWidth = stage.getWidth();
      parentHeight = stage.getHeight();
    } else {
      parentWidth = parent.getWidth();
      parentHeight = parent.getHeight();
    }
    setSize(parentWidth, parentHeight);
  }
  if (!needsLayout) return;
  needsLayout = false;
  layout();
}

代码示例来源:origin: langurmonkey/gaiasky

@Override
public float[] getPositionAndSizeGui(String name) {
  IGui gui = GaiaSky.instance.mainGui;
  Actor actor = gui.getGuiStage().getRoot().findActor(name);
  if (actor != null) {
    float x = actor.getX();
    float y = actor.getY();
    // x and y relative to parent, so we need to add coordinates of
    // parents up to top
    Group parent = actor.getParent();
    while (parent != null) {
      x += parent.getX();
      y += parent.getY();
      parent = parent.getParent();
    }
    return new float[] { x, y, actor.getWidth(), actor.getHeight() };
  } else {
    return null;
  }
}

代码示例来源:origin: 121077313/cocostudio-ui-libgdx

@Override
public Actor parse(CocoCreatorUIEditor editor, final ObjectData widget) {
  Group group = new Group();
  for (AANode cNode : widget._components) {
    Actor childrenActor = editor.parseWidget(group, (ObjectData) cNode);
    if (childrenActor == null) {
      continue;
    }
    
    group.addActor(childrenActor);
  }
  return group;
}

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

private void updateGroupProperties( ExternalGroupModel model, Group group){
    group.setName( model.getName());
    model.setWidth( group.getWidth());
    model.setHeight( group.getHeight());
    
    // For example .. <FriendsPanel > in top xml and its implementation's root group (FriendsPanel.xml file's) 
    // should both be visible=true in order to set whole group visible, if at least one of them set to false 
    // whole group will be invisible.
    group.setVisible(model.isVisible() && group.isVisible());
    
    Vector2 screenPos;
    if (model.getScreenAlignmentSupport() == null) {
      screenPos = calculateScreenPosition(model.getScreenAlignment(), model);
    } else {
      screenPos = calculateScreenPosition(model.getScreenAlignment(), model.getScreenAlignmentSupport(), model);
    }

    if (screenPos != null) {
      group.setPosition(screenPos.x, screenPos.y);
    } else {
      float positionMultiplier = resolutionHelper.getPositionMultiplier();
      group.setPosition(model.getX() * positionMultiplier, model.getY() * positionMultiplier);
    }

    setScaleProperty(model, group);
  }
}

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

/** Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the
 * group. */
public <T extends Actor> T findActor (String name) {
  Array<Actor> children = this.children;
  for (int i = 0, n = children.size; i < n; i++)
    if (name.equals(children.get(i).getName())) return (T)children.get(i);
  for (int i = 0, n = children.size; i < n; i++) {
    Actor child = children.get(i);
    if (child instanceof Group) {
      Actor actor = ((Group)child).findActor(name);
      if (actor != null) return (T)actor;
    }
  }
  return null;
}

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

/** @return May be null. */
private TextField findNextTextField (Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords,
  boolean up) {
  for (int i = 0, n = actors.size; i < n; i++) {
    Actor actor = actors.get(i);
    if (actor instanceof TextField) {
      if (actor == this) continue;
      TextField textField = (TextField)actor;
      if (textField.isDisabled() || !textField.focusTraversal || !textField.ancestorsVisible()) continue;
      Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY()));
      boolean below = actorCoords.y != currentCoords.y && (actorCoords.y < currentCoords.y ^ up);
      boolean right = actorCoords.y == currentCoords.y && (actorCoords.x > currentCoords.x ^ up);
      if (!below && !right) continue;
      boolean better = best == null || (actorCoords.y != bestCoords.y && (actorCoords.y > bestCoords.y ^ up));
      if (!better) better = actorCoords.y == bestCoords.y && (actorCoords.x < bestCoords.x ^ up);
      if (better) {
        best = (TextField)actor;
        bestCoords.set(actorCoords);
      }
    } else if (actor instanceof Group)
      best = findNextTextField(((Group)actor).getChildren(), best, bestCoords, currentCoords, up);
  }
  return best;
}

代码示例来源:origin: bladecoder/bladecoder-adventure-engine

@Override
  public void changed(ChangeEvent event, com.badlogic.gdx.scenes.scene2d.Actor actor) {
    if (toolsButton.isChecked()) {
      scnWidget.getParent().addActor(toolsWindow);
      toolsWindow.setPosition(getScnWidget().getX() + 5, getScnWidget().getY() + 5);
      toolsWindow.invalidate();
    } else {
      scnWidget.getParent().removeActor(toolsWindow);
    }
  }
});

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

public T show(Group group, float sx, float sy, int aglin) {
  group.addActor(t);
  t.setPosition(group.getWidth() * sx, group.getHeight() * sy, aglin);
  return t;
}

代码示例来源:origin: lycying/c2d-engine

@Override
  public void onLoadedResourcesCompleted() {
    final TextureAtlas bgAtlas = Engine.resource("bgAtlas", TextureAtlas.class);
    rbg = new ParallaxGroup(480, 320, new Vector2(50, 100));
    rbg.addActor(new Image(new AdvanceSprite(bgAtlas.findRegion("bg"))));
    rbg.addActor(new ParallaxLayer(rbg, new Image(new AdvanceSprite(bgAtlas.findRegion("cloud"))), new Vector2(0.5f, 0), new Vector2(0, 1000), new Vector2(0, 70)));
    rbg.addActor(new ParallaxLayer(rbg, new Image(new AdvanceSprite(bgAtlas.findRegion("front"))), new Vector2(1f, 0), new Vector2(0, 1000), new Vector2()));
    rbg.addActor(new ParallaxLayer(rbg, new Image(new AdvanceSprite(bgAtlas.findRegion("dock-tree"))), new Vector2(1f, 0), new Vector2(1000, 1000), new Vector2()));
    rbg.addAction(Actions.forever(Actions.sequence(
        ParallaxGroupSpeedToAction.obtain(1000, 300, 1),
        ParallaxGroupSpeedToAction.obtain(50, 300, 2),
        Actions.scaleTo(2, 2, 0.5f),
        Actions.scaleTo(1, 1, 1.5f)
    )));
    final SceneStage stage = new SceneStage();
    final Group group = new Group();
    group.setScale(Engine.getWidth() / 480f);
    group.addActor(rbg);
    stage.addActor(group);
    Engine.setMainScene(stage);
  }
}

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

console = new Group();
console.setVisible(false);
    .click(() -> {
      buuleable(false);
      console.setVisible(true);
    });
pane.setPosition(0, 45);
console.addActor(pane);
  console.setVisible(false);
  buuleable(true);
});

相关文章

微信公众号

最新文章

更多