use of com.badlogic.gdx.scenes.scene2d.Group in project netthreads-libgdx by alistairrutherford.
the class SceneHelper method intersects.
/**
* Look for intersection between two actors.
*
* I have defined this here as I can't extend the base classes Actor and Group.
*
* @param x
* The x pos rectangle.
* @param y
* The y pos rectangle.
* @param width
* The rectangle width.
* @param height
* The rectangle height.
* @param group
* The group.
* @param targetClass
* The target class.
*
* @return Target class, null if no intersection.
*/
@SuppressWarnings("rawtypes")
public static Actor intersects(float x, float y, float width, float height, Group group, Class targetClass) {
SnapshotArray<Actor> children = group.getChildren();
Actor hit = null;
int index = children.size - 1;
while (hit == null && index >= 0) {
Actor child = children.get(index);
point.x = x;
point.y = y;
group.localToDescendantCoordinates(child, point);
// intersection
if (child.getClass().equals(targetClass)) {
if (isIntersect(point.x, point.y, width, height, 0, 0, child.getWidth(), child.getHeight())) {
hit = child;
}
} else if (child instanceof Group) {
hit = intersects(point.x, point.y, width, height, (Group) child, targetClass);
}
index--;
}
return hit;
}
use of com.badlogic.gdx.scenes.scene2d.Group in project libgdx by libgdx.
the class CpuSpriteBatchTest method create.
public void create() {
Batch batch = new CpuSpriteBatch();
// batch = new SpriteBatch();
stage = new Stage(new ExtendViewport(500, 500), batch);
Gdx.input.setInputProcessor(stage);
texture = new Texture("data/bobargb8888-32x32.png");
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture));
for (int i = 0; i < NUM_GROUPS; i++) {
Group group = createActorGroup(drawable);
stage.addActor(group);
}
}
use of com.badlogic.gdx.scenes.scene2d.Group in project libgdx by libgdx.
the class CpuSpriteBatchTest method createActorGroup.
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;
}
use of com.badlogic.gdx.scenes.scene2d.Group in project libgdx by libgdx.
the class Widget method invalidateHierarchy.
public void invalidateHierarchy() {
if (!layoutEnabled)
return;
invalidate();
Group parent = getParent();
if (parent instanceof Layout)
((Layout) parent).invalidateHierarchy();
}
use of com.badlogic.gdx.scenes.scene2d.Group in project libgdx by libgdx.
the class TextField method findNextTextField.
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 == this)
continue;
if (actor instanceof TextField) {
TextField textField = (TextField) actor;
if (textField.isDisabled() || !textField.focusTraversal)
continue;
Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY()));
if ((actorCoords.y < currentCoords.y || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x)) ^ up) {
if (best == null || (actorCoords.y > bestCoords.y || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x)) ^ up) {
best = (TextField) actor;
bestCoords.set(actorCoords);
}
}
} else if (actor instanceof Group)
best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up);
}
return best;
}
Aggregations