Search in sources :

Example 1 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project netthreads-libgdx by alistairrutherford.

the class Layer method mouseMoved.

@Override
public boolean mouseMoved(int x, int y) {
    boolean handled = false;
    SnapshotArray<Actor> list = getChildren();
    int size = list.size;
    int index = 0;
    while (index < size && !handled) {
        Actor actor = list.get(index);
        if (actor instanceof Layer) {
            Layer layer = (Layer) actor;
            handled = layer.mouseMoved(x, y);
        }
        index++;
    }
    return handled;
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 2 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor 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 3 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor 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 Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.

the class Benchmark3DTest method create.

@Override
public void create() {
    super.create();
    GLProfiler.enable();
    randomizeLights();
    cam.position.set(10, 10, 10);
    cam.lookAt(0, 0, 0);
    cam.update();
    showAxes = true;
    lighting = true;
    vertexCountLabel = new Label("Vertices: 999", skin);
    vertexCountLabel.setPosition(0, fpsLabel.getTop());
    hud.addActor(vertexCountLabel);
    textureBindsLabel = new Label("Texture bindings: 999", skin);
    textureBindsLabel.setPosition(0, vertexCountLabel.getTop());
    hud.addActor(textureBindsLabel);
    shaderSwitchesLabel = new Label("Shader switches: 999", skin);
    shaderSwitchesLabel.setPosition(0, textureBindsLabel.getTop());
    hud.addActor(shaderSwitchesLabel);
    drawCallsLabel = new Label("Draw calls: 999", skin);
    drawCallsLabel.setPosition(0, shaderSwitchesLabel.getTop());
    hud.addActor(drawCallsLabel);
    glCallsLabel = new Label("GL calls: 999", skin);
    glCallsLabel.setPosition(0, drawCallsLabel.getTop());
    hud.addActor(glCallsLabel);
    lightsLabel = new Label("Lights: 999", skin);
    lightsLabel.setPosition(0, glCallsLabel.getTop());
    hud.addActor(lightsLabel);
    lightingCheckBox = new CheckBox("Lighting", skin);
    lightingCheckBox.setChecked(lighting);
    lightingCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            lighting = lightingCheckBox.isChecked();
        }
    });
    lightingCheckBox.setPosition(hudWidth - lightingCheckBox.getWidth(), gridCheckBox.getTop());
    hud.addActor(lightingCheckBox);
    lightsCheckBox = new CheckBox("Randomize lights", skin);
    lightsCheckBox.setChecked(false);
    lightsCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            lightsCheckBox.setChecked(false);
            randomizeLights();
        }
    });
    lightsCheckBox.setPosition(hudWidth - lightsCheckBox.getWidth(), lightingCheckBox.getTop());
    hud.addActor(lightsCheckBox);
    moveCheckBox.remove();
    rotateCheckBox.remove();
}
Also used : ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 5 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.

the class DragAndDrop method addSource.

public void addSource(final Source source) {
    DragListener listener = new DragListener() {

        public void dragStart(InputEvent event, float x, float y, int pointer) {
            if (activePointer != -1) {
                event.stop();
                return;
            }
            activePointer = pointer;
            dragStartTime = System.currentTimeMillis();
            payload = source.dragStart(event, getTouchDownX(), getTouchDownY(), pointer);
            event.stop();
            if (cancelTouchFocus && payload != null)
                source.getActor().getStage().cancelTouchFocusExcept(this, source.getActor());
        }

        public void drag(InputEvent event, float x, float y, int pointer) {
            if (payload == null)
                return;
            if (pointer != activePointer)
                return;
            Stage stage = event.getStage();
            Touchable dragActorTouchable = null;
            if (dragActor != null) {
                dragActorTouchable = dragActor.getTouchable();
                dragActor.setTouchable(Touchable.disabled);
            }
            // Find target.
            Target newTarget = null;
            isValidTarget = false;
            float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY;
            // Prefer touchable actors.
            Actor hit = event.getStage().hit(stageX, stageY, true);
            if (hit == null)
                hit = event.getStage().hit(stageX, stageY, false);
            if (hit != null) {
                for (int i = 0, n = targets.size; i < n; i++) {
                    Target target = targets.get(i);
                    if (!target.actor.isAscendantOf(hit))
                        continue;
                    newTarget = target;
                    target.actor.stageToLocalCoordinates(tmpVector.set(stageX, stageY));
                    break;
                }
            }
            // If over a new target, notify the former target that it's being left behind.
            if (newTarget != target) {
                if (target != null)
                    target.reset(source, payload);
                target = newTarget;
            }
            // Notify new target of drag.
            if (newTarget != null)
                isValidTarget = newTarget.drag(source, payload, tmpVector.x, tmpVector.y, pointer);
            if (dragActor != null)
                dragActor.setTouchable(dragActorTouchable);
            // Add/remove and position the drag actor.
            Actor actor = null;
            if (target != null)
                actor = isValidTarget ? payload.validDragActor : payload.invalidDragActor;
            if (actor == null)
                actor = payload.dragActor;
            if (actor == null)
                return;
            if (dragActor != actor) {
                if (dragActor != null)
                    dragActor.remove();
                dragActor = actor;
                stage.addActor(actor);
            }
            float actorX = event.getStageX() - actor.getWidth() + dragActorX;
            float actorY = event.getStageY() + dragActorY;
            if (keepWithinStage) {
                if (actorX < 0)
                    actorX = 0;
                if (actorY < 0)
                    actorY = 0;
                if (actorX + actor.getWidth() > stage.getWidth())
                    actorX = stage.getWidth() - actor.getWidth();
                if (actorY + actor.getHeight() > stage.getHeight())
                    actorY = stage.getHeight() - actor.getHeight();
            }
            actor.setPosition(actorX, actorY);
        }

        public void dragStop(InputEvent event, float x, float y, int pointer) {
            if (pointer != activePointer)
                return;
            activePointer = -1;
            if (payload == null)
                return;
            if (System.currentTimeMillis() - dragStartTime < dragTime)
                isValidTarget = false;
            if (dragActor != null)
                dragActor.remove();
            if (isValidTarget) {
                float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY;
                target.actor.stageToLocalCoordinates(tmpVector.set(stageX, stageY));
                target.drop(source, payload, tmpVector.x, tmpVector.y, pointer);
            }
            source.dragStop(event, x, y, pointer, payload, isValidTarget ? target : null);
            if (target != null)
                target.reset(source, payload);
            payload = null;
            target = null;
            isValidTarget = false;
            dragActor = null;
        }
    };
    listener.setTapSquareSize(tapSquareSize);
    listener.setButton(button);
    source.actor.addCaptureListener(listener);
    sourceListeners.put(source, listener);
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Touchable(com.badlogic.gdx.scenes.scene2d.Touchable)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)67 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)26 Stage (com.badlogic.gdx.scenes.scene2d.Stage)19 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)19 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)18 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)15 Layout (com.badlogic.gdx.scenes.scene2d.utils.Layout)11 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)10 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)9 Texture (com.badlogic.gdx.graphics.Texture)8 Group (com.badlogic.gdx.scenes.scene2d.Group)8 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)6 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)6 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)6 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)5 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)5 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)5