Example usage for com.badlogic.gdx InputMultiplexer InputMultiplexer

List of usage examples for com.badlogic.gdx InputMultiplexer InputMultiplexer

Introduction

In this page you can find the example usage for com.badlogic.gdx InputMultiplexer InputMultiplexer.

Prototype

public InputMultiplexer(InputProcessor... processors) 

Source Link

Usage

From source file:com.badlogic.gdx.tests.dragome.examples.GearsDemo.java

@Override
public void create() {

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .2f, .2f, .2f, 2f));
    //      environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0f, -0.5f, -0.5f));

    sl = new PointLight().setPosition(-5, 10, -6).setColor(1, 1, 1, 1).setIntensity(150);

    //      sl2 = new PointLight().setPosition(0, 7, 5).setColor(0.3f, 0.8f, 0.3f, 1)
    //         .setIntensity(20);
    ///*from  w  ww  .  ja va2 s .  c om*/
    //      sl3 = new PointLight().setPosition(0, 9, 6).setColor(0.3f, 0.3f, 0.8f, 1)
    //         .setIntensity(20);

    environment.add(sl);
    //      environment.add(sl2);
    //      environment.add(sl3);

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(-10, 3, 10f);
    cam.lookAt(-3, 0, 0);
    cam.near = 1f;
    cam.far = 100f;
    cam.update();

    cameraController = new CameraInputController(cam);
    cameraController.autoUpdate = false;
    cameraController.forwardTarget = false;
    cameraController.translateTarget = false;

    Gdx.input.setInputProcessor(new InputMultiplexer(cameraController));

    time = TimeUtils.millis();

    viewport = new ScreenViewport(cam);
    guiViewport = new ScreenViewport();

    DefaultShaderProvider defaultShaderProvider = new DefaultShaderProvider();
    modelBatch = new ModelBatch(defaultShaderProvider);

    ModelBuilder modelBuilder = new ModelBuilder();
    model1 = gear(modelBuilder, 1.0f, 4.0f, 1.0f, 20, 0.7f, Color.RED);
    gear1 = new ModelInstance(model1);

    model2 = gear(modelBuilder, 0.5f, 2.0f, 2.0f, 10, 0.7f, Color.GREEN);
    gear2 = new ModelInstance(model2);

    model3 = gear(modelBuilder, 1.3f, 2.0f, 1.5f, 10, 0.7f, Color.BLUE);
    gear3 = new ModelInstance(model3);

    font = new BitmapFont();

    batch = new SpriteBatch();

    lightModel = modelBuilder.createSphere(1, 1, 1, 10, 10,
            new Material(ColorAttribute.createDiffuse(1, 1, 1, 1)), Usage.Position);
    lightModel.nodes.get(0).parts.get(0).setRenderable(pLight = new Renderable());
}

From source file:com.jlabarca.director.Scene.java

License:Apache License

/**
 * Constructor where we supply our own sprite batch.
 * /*from   w  w  w . j a v a  2s  .c  om*/
 * @param width
 * @param height
 * @param stretch
 * @param batch
 */
public Scene(float width, float height, boolean stretch, Batch batch) {
    super(new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
            new OrthographicCamera()), batch);
    //super();
    inputMultiplexer = new InputMultiplexer(this);

    nodes = new Array<Node>(DEFAULT_LAYER_CAPACITY);
}

From source file:com.netthreads.libgdx.scene.Scene.java

License:Apache License

/**
 * Constructor where we supply our own sprite batch.
 *
 * @param width/*from ww w.j  a v  a  2  s  . c om*/
 * @param height
 * @param stretch
 * @param batch
 */
public Scene(Viewport viewport, SpriteBatch batch) {
    super(viewport, batch);
    //   super(width, height, stretch, batch);

    inputMultiplexer = new InputMultiplexer(this);

    nodes = new Array<Node>(DEFAULT_LAYER_CAPACITY);
}

From source file:net.mostlyoriginal.blackjack.BlackjackGame.java

public BlackjackGame() {
    commander = new EventCommander();
    phaseSystemsMap = new HashMap<BlackJackSystems, BaseBlackjackSystem>();
    IGetPhaseFromId resolver = new IGetPhaseFromId() {
        @Override//from w ww . ja  va 2  s.co m
        public BaseBlackjackSystem system(BlackJackSystems name) {
            return phaseSystemsMap.get(name);
        }
    };
    phaseSystemsMap.put(BlackJackSystems.CountCheck, new CountCheckSystem(resolver));
    phaseSystemsMap.put(BlackJackSystems.DealHidden, new DealHiddenSystem(resolver));
    phaseSystemsMap.put(BlackJackSystems.DealShown, new DealShownSystem(resolver));
    phaseSystemsMap.put(BlackJackSystems.PlayerChoice, new PlayerChoiceSystem(resolver));
    phaseSystemsMap.put(BlackJackSystems.CleanupSystem, new CleanupSystem(resolver));
    phaseSystemsMap.put(BlackJackSystems.UpdateWinnerPlayerSystem, new UpdateWinnerSystem(resolver));
    phaseSystemsMap.put(BlackJackSystems.SelectNextPlayer, new SelectNextPlayerSystem(resolver, 2));
    cardgameFramework = CardgameFramework.builder().victoryChecker(new IVictoryDecider() {
        @Override
        public boolean isVictoryCondition() {
            return mGameEnd.get();
        }
    }).phaseSystems(new ArrayList<BasePhaseSystem>(phaseSystemsMap.values()))
            .startingSystem(phaseSystemsMap.get(BlackJackSystems.SelectNextPlayer)).eventCommander(commander)
            .build();
    InputMultiplexer inputMultiplexer = new InputMultiplexer(new InputAdapter() {
        @Override
        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.ESCAPE) {
                mGameEnd.set(true);
            }
            return super.keyDown(keycode);
        }
    });
    Gdx.input.setInputProcessor(inputMultiplexer);
    initBlackJack();
}

From source file:rosthouse.rosty.systems.InputSystem.java

public InputSystem() {
    super(Family.one(VelocityComponent.class).get());
    Gdx.app.log("INPUTSYSTEM", "Loading Input System");
    multiplexer = new InputMultiplexer(this);
    Gdx.input.setInputProcessor(multiplexer);
    Gdx.input.setCatchMenuKey(true);/*from  w  w w .j a  v  a 2s  . c om*/
    Gdx.input.setCatchBackKey(true);
}

From source file:rx.libgdx.sources.GdxInputEventSource.java

License:Apache License

/**
 * @see rx.GdxObservable#fromInput//from w  w  w .  ja v a2 s.  c o m
 */
public static Observable<InputEvent> fromInput() {
    return create(new Observable.OnSubscribe<InputEvent>() {

        @Override
        public void call(final Subscriber<? super InputEvent> subscriber) {
            final InputProcessor processor = new InputProcessor() {

                @Override
                public boolean touchUp(int screenX, int screenY, int pointer, int button) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new TouchUpEvent(screenX, screenY, pointer, button));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean touchDown(int screenX, int screenY, int pointer, int button) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new TouchDownEvent(screenX, screenY, pointer, button));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean touchDragged(int screenX, int screenY, int pointer) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new TouchDraggedEvent(screenX, screenY, pointer));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean keyDown(int keycode) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new KeyDownEvent(keycode));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean keyUp(int keycode) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new KeyUpEvent(keycode));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean keyTyped(char character) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new KeyTypedEvent(character));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean mouseMoved(int screenX, int screenY) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new MouseMovedEvent(screenX, screenY));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean scrolled(int amount) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new ScrolledEvent(amount));
                        return true;
                    }
                    return false;
                }

            };

            final InputProcessor wrapped = Gdx.input.getInputProcessor();
            final InputMultiplexer im;
            if (wrapped instanceof InputMultiplexer) {
                im = (InputMultiplexer) wrapped;
            } else if (wrapped != null) {
                im = new InputMultiplexer(wrapped);
            } else {
                im = new InputMultiplexer();
            }

            im.addProcessor(processor);

            subscriber.add(Subscriptions.create(new Action0() {

                @Override
                public void call() {
                    im.removeProcessor(processor);
                    if (wrapped != null && wrapped != im && im.size() == 1) {
                        Gdx.input.setInputProcessor(wrapped);
                    }
                }

            }));

            Gdx.input.setInputProcessor(im);
        }

    });
}