Search in sources :

Example 1 with Group

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;
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 2 with Group

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);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Group(com.badlogic.gdx.scenes.scene2d.Group) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Batch(com.badlogic.gdx.graphics.g2d.Batch) CpuSpriteBatch(com.badlogic.gdx.graphics.g2d.CpuSpriteBatch) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) CpuSpriteBatch(com.badlogic.gdx.graphics.g2d.CpuSpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 3 with 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;
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 4 with 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();
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout)

Example 5 with Group

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;
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Vector2(com.badlogic.gdx.math.Vector2) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Aggregations

Group (com.badlogic.gdx.scenes.scene2d.Group)14 Actor (com.badlogic.gdx.scenes.scene2d.Actor)8 Stage (com.badlogic.gdx.scenes.scene2d.Stage)5 Texture (com.badlogic.gdx.graphics.Texture)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 Layout (com.badlogic.gdx.scenes.scene2d.utils.Layout)2 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 CpuSpriteBatch (com.badlogic.gdx.graphics.g2d.CpuSpriteBatch)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 Vector2 (com.badlogic.gdx.math.Vector2)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)1 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)1