Search in sources :

Example 61 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 62 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 63 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 64 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 65 with Actor

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

the class FishMiniGame method setupPauseMenu.

/** Create the pause menu. */
private void setupPauseMenu() {
    pauseMenu = new Stage(new ScreenViewport(), game.batch);
    Table table = new Table();
    table.setFillParent(true);
    table.center();
    pauseMenu.addActor(table);
    TextButton resumeButton = new TextButton("Resume", game.assets.skin);
    resumeButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            paused = false;
        }
    });
    table.add(resumeButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
    table.row();
    TextButton settingsButton = new TextButton("Settings", game.assets.skin);
    final Screen sourceScreen = this;
    settingsButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            game.settingsScreen.setSourceScreen(sourceScreen);
            game.setScreen(game.settingsScreen);
        }
    });
    table.add(settingsButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
    table.row();
    TextButton quitButton = new TextButton("Quit", game.assets.skin);
    quitButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            game.save.setLevel(game.save.getLevel() - 1);
            game.setScreen(game.menuScreen);
        }
    });
    table.add(quitButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Screen(com.badlogic.gdx.Screen) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport)

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