Search in sources :

Example 56 with Actor

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

the class SceneHelper method hit.

/**
	 * Find hit class.
	 * 
	 * @param x
	 *            Current x position.
	 * @param y
	 *            Current y position
	 * @param group
	 *            The starting Group.
	 * @param targetClass
	 *            The target class type.
	 * 
	 * @return The target or null if not found.
	 */
@SuppressWarnings("rawtypes")
public static Actor hit(float x, float y, Group group, Class targetClass) {
    SnapshotArray<Actor> children = group.getChildren();
    Actor hit = null;
    boolean found = false;
    int index = children.size - 1;
    while (!found && index >= 0) {
        Actor child = children.get(index);
        if (child.getClass().isAssignableFrom(targetClass)) {
            point.x = x;
            point.y = y;
            group.localToDescendantCoordinates(child, point);
            if (child.hit(point.x, point.y, true) != null) {
                found = true;
                hit = child;
            } else if (child instanceof Group) {
                child = hit(x, y, (Group) child, targetClass);
            }
        }
        index--;
    }
    return hit;
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 57 with Actor

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

the class SceneHelper method hit.

/**
	 * Look for target hit of specified class.
	 * 
	 * @param x
	 *            Current x position.
	 * @param y
	 *            Current y position
	 * @param stage
	 *            The starting stage.
	 * @param targetClass
	 *            The target class type.
	 * @return Target class or null if not found.
	 */
@SuppressWarnings("rawtypes")
public static Actor hit(float x, float y, Stage stage, Class targetClass) {
    Group root = stage.getRoot();
    SnapshotArray<Actor> children = root.getChildren();
    Actor hit = null;
    boolean found = false;
    int index = children.size - 1;
    while (!found && index >= 0) {
        Actor child = children.get(index);
        point.x = x;
        point.y = y;
        root.localToDescendantCoordinates(child, point);
        Actor childHit = root.hit(point.x, point.y, true);
        if (childHit != null && childHit.getClass().isAssignableFrom(targetClass)) {
            found = true;
            hit = childHit;
        } else {
            index--;
        }
    }
    return hit;
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 58 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project Catacomb-Snatch by Catacomb-Snatch.

the class Scene method tick.

@Override
public void tick(float delta) {
    // Draw background
    if (drawBackground && background != null) {
        getBatch().begin();
        getBatch().setColor(backgroundColor);
        getBatch().draw(background, 0, 0, Screen.getWidth(), Screen.getHeight());
        getBatch().end();
    }
    // Updating mouse dependent stuff in render()
    if (!Gdx.input.isTouched()) {
        mousePos = screenToStageCoordinates(mousePos.set(Gdx.input.getX(), Gdx.input.getY()));
        for (Actor a : getActors()) {
            currentActorRect.set(a.getX(), a.getY(), a.getWidth(), a.getHeight());
            for (EventListener el : a.getListeners()) {
                if (!(el instanceof InputListener))
                    continue;
                InputListener il = (InputListener) el;
                if (currentActorRect.contains(mousePos.x, mousePos.y)) {
                    il.enter(null, mousePos.x, mousePos.y, -1, null);
                } else {
                    il.exit(null, mousePos.x, mousePos.y, -1, null);
                }
            }
        }
    }
    super.draw();
    getBatch().begin();
}
Also used : InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener)

Example 59 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project Entitas-Java by Rubentxu.

the class GUIManagerGDX method createGUIElement.

@Override
public Actor createGUIElement(String name) {
    GUIFactory<Actor, GUIManagerGDX> factory = guiFactories.get(name);
    Actor element = null;
    if (factory != null) {
        element = factory.create(this);
    }
    return element;
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 60 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project Entitas-Java by Rubentxu.

the class GuiFactory method createTouchPad.

public Touchpad createTouchPad(float width, float height, InputEntity player) {
    Touchpad touchpad = new Touchpad(10 * ScaleUtil.getSizeRatio(), skin);
    touchpad.setPosition(25 * ScaleUtil.getSizeRatio(), 15);
    touchpad.setWidth(width);
    touchpad.setHeight(height);
    PlayerInputController stateController = player.getPlayerInputController();
    touchpad.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("PercentX " + ((Touchpad) actor).getKnobPercentX() + "PercentY " + ((Touchpad) actor).getKnobPercentY());
            if (((Touchpad) actor).getKnobPercentX() == 0 || ((Touchpad) actor).getKnobPercentX() < 0.5 && ((Touchpad) actor).getKnobPercentX() > -0.5) {
                //                    controller.rightReleased();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() > 0.5) {
                //                    controller.rightPressed();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, true, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() < -0.5) {
                //                    controller.leftPressed();
                //                    controller.rightReleased();
                player.replacePlayerInputController(true, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentY() > 0.5) {
                //                    controller.jumpPressed();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            } else {
                //                    controller.jumpReleased();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
            }
        }
    });
    return touchpad;
}
Also used : PlayerInputController(com.ilargia.games.states.game.component.input.PlayerInputController) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

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