List of usage examples for com.badlogic.gdx InputMultiplexer InputMultiplexer
public InputMultiplexer()
From source file:pl.kotcrab.libgdx.util.RectangleDrawer.java
License:Apache License
public void attachInputProcessor() { if (Gdx.input.getInputProcessor() == null) { Gdx.input.setInputProcessor(this); return;/*from w w w .j a va2 s . com*/ } if (Gdx.input.getInputProcessor() instanceof InputMultiplexer) { InputMultiplexer mul = (InputMultiplexer) Gdx.input.getInputProcessor(); mul.addProcessor(this); Gdx.input.setInputProcessor(mul); } else { InputMultiplexer mul = new InputMultiplexer(); mul.addProcessor(Gdx.input.getInputProcessor()); mul.addProcessor(this); Gdx.input.setInputProcessor(mul); } }
From source file:scene3d.demo.Scene3dDemo.java
License:Apache License
@Override public void create() { //2d stuff/*from w ww . j a va 2 s . com*/ stage2d = new Stage(); skin = new Skin(Gdx.files.internal("skin/uiskin.json")); fpsLabel = new Label("ff", skin); fpsLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 40); visibleLabel = new Label("ff", skin); visibleLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 60); positionLabel = new Label("Position", skin); positionLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 80); rotationLabel = new Label("Rotation", skin); rotationLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 100); positionCameraLabel = new Label("Position", skin); positionCameraLabel.setPosition(20, Gdx.graphics.getHeight() - 40); rotationCameraLabel = new Label("Rotation", skin); rotationCameraLabel.setPosition(20, Gdx.graphics.getHeight() - 60); stage2d.addActor(fpsLabel); stage2d.addActor(visibleLabel); stage2d.addActor(positionLabel); stage2d.addActor(rotationLabel); stage2d.addActor(positionCameraLabel); stage2d.addActor(rotationCameraLabel); stage2d.addListener(new InputListener() { @Override public boolean keyUp(InputEvent event, int keycode) { if (keycode == Keys.LEFT) leftKey = false; if (keycode == Keys.RIGHT) rightKey = false; if (keycode == Keys.UP) upKey = false; if (keycode == Keys.DOWN) downKey = false; if (keycode == Keys.SPACE) spaceKey = false; return super.keyUp(event, keycode); } @Override public boolean keyDown(InputEvent event, int keycode) { if (keycode == Keys.LEFT) leftKey = true; if (keycode == Keys.RIGHT) rightKey = true; if (keycode == Keys.UP) upKey = true; if (keycode == Keys.DOWN) downKey = true; if (keycode == Keys.SPACE) spaceKey = true; return super.keyDown(event, keycode); } }); //3dstuff stage3d = new Stage3d(); modelBuilder = new ModelBuilder(); model = modelBuilder.createBox(5f, 5f, 5f, new Material("Color", ColorAttribute.createDiffuse(Color.WHITE)), Usage.Position | Usage.Normal); model2 = modelBuilder.createBox(2f, 2f, 2f, new Material("Color", ColorAttribute.createDiffuse(Color.WHITE)), Usage.Position | Usage.Normal); actor2 = new Actor3d(model2, 10f, 0f, 0f); model3 = modelBuilder.createBox(2f, 2f, 2f, new Material("Color", ColorAttribute.createDiffuse(Color.ORANGE)), Usage.Position | Usage.Normal); actor3 = new Actor3d(model3, -10f, 0f, 0f); actor2.setColor(Color.RED); actor2.setName("actor2"); actor3.setName("actor3"); camController = new CameraInputController(stage3d.getCamera()); InputMultiplexer im = new InputMultiplexer(); im.addProcessor(stage2d);// 2d should get click events first //im.addProcessor(stage3d); im.addProcessor(camController); Gdx.input.setInputProcessor(im); stage3d.touchable = Touchable.enabled; // only then will it detect hit actor3d ModelBuilder builder = new ModelBuilder(); builder.begin(); MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material()); for (float x = -200f; x < 200f; x += 10f) { for (float z = -200f; z < 200f; z += 10f) { part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0); } } floor = new Actor3d(builder.end()); AssetManager am = new AssetManager(); am.load("data/g3d/knight.g3db", Model.class); am.load("data/g3d/skydome.g3db", Model.class); am.load("data/g3d/concrete.png", Texture.class); am.finishLoading(); knight = new Actor3d(am.get("data/g3d/knight.g3db", Model.class), 0f, 18f, 0f); knight.getAnimation().inAction = true; knight.getAnimation().animate("Walk", -1, 1f, null, 0.2f); skydome = new Actor3d(am.get("data/g3d/skydome.g3db", Model.class)); floor.materials.get(0).set(TextureAttribute.createDiffuse(am.get("data/g3d/concrete.png", Texture.class))); stage3d.addActor3d(skydome); stage3d.addActor3d(floor); knight.setPitch(-90f); knight.setYaw(-130f); testActor3d(); //stage3d.addAction3d(Actions3d.rotateBy(0f, 90f, 0f, 2f)); //testGroup3d(); //testStage3d(); }
From source file:se.danielj.geometridestroyer.Core.java
License:GNU General Public License
@Override public void create() { SpriteManager.init();// ww w . j a va2s . c om FontManager.init(); MusicManager.init(); gameInput = new InputMultiplexer(); levelScreenInput = new InputMultiplexer(); creditsInput = new InputMultiplexer(); game = new GeometriDestroyer(this, gameInput); levelScreen = new LevelScreen(this, levelScreenInput); credits = new Credits(this, creditsInput); Gdx.input.setInputProcessor(levelScreenInput); Gdx.input.setCatchBackKey(true); setScreen(levelScreen); MusicManager.play(true); }
From source file:se.danielj.skuttandenyancat.AppController.java
License:GNU General Public License
@Override public void create() { SpriteManager.init();/*w w w . j ava2s . c om*/ FontManager.init(); MusicManager.init(); SoundEffectsManager.init(); menuInputMultiplexer = new InputMultiplexer(); menuScene = new MainMenu(this, menuInputMultiplexer); menuScene.create(); gameInputMultiplexer = new InputMultiplexer(); gameScene = new Game(this, gameInputMultiplexer); gameScene.create(); creditsInputMultiplexer = new InputMultiplexer(); creditsScene = new Credits(this, creditsInputMultiplexer); creditsScene.create(); setScene(Scene.MAIN_MENU); Gdx.input.setCatchBackKey(true); }
From source file:se.danielj.slashatthegame.Game.java
License:GNU General Public License
@Override public void create() { SpriteManager.init();// ww w . jav a 2s . c o m FontManager.init(); SoundEffectsManager.init(); MusicManager.init(); Gdx.input.setCatchBackKey(true); if (world != null) { disposeSystems(world); } world = new World(); world.setManager(new GroupManager()); box2dWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(0, -3), true); stage = new Stage(960, 540, false); if (tweenManager == null) { tweenManager = new TweenManager(); } inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(stage); inputMultiplexer.addProcessor(this); Gdx.input.setInputProcessor(inputMultiplexer); final LabelStyle labelStyle = new LabelStyle(); labelStyle.font = FontManager.getNormalFont(); labelStyle.fontColor = new Color(0, 0, 0, 1); if (level == 0) { final Song song = new Song(MusicManager.getSong(MusicManager.THEME)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 2f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("logo")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("logo")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); level = 1; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); return false; } }); button.setBounds(0, 0, stage.getWidth(), stage.getHeight()); stage.addActor(button); logic = new Logic() { @Override public void render() { timer += Gdx.graphics.getDeltaTime(); tweenManager.update(Gdx.graphics.getDeltaTime()); stage.draw(); stage.act(world.getDelta()); } }; } else if (level == 1) { Progress.init(); world.setSystem(new SpriteRenderSystem()); world.setSystem(new EffectSystem()); world.setSystem(new TableSystem()); world.setSystem(new PhysicsSystem(box2dWorld)); world.initialize(); EntityCreator.createRoomT(world).addToWorld(); EntityCreator.createTableT(world).addToWorld(); EntityCreator.createTommieT(world).addToWorld(); final Entity glow = EntityCreator.createGlow(world, 132, 6); glow.addToWorld(); glow.disable(); timer = 0; health = 3; progressSpeed = -2; progressing = false; won = false; final Song song = new Song(MusicManager.getSong(MusicManager.TOMMIE)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("button")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("button_pressed")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); progressing = true; progressSpeed = -progressSpeed; if (health == 3 && Math.abs(progressSpeed) == 2.0) { glow.enable(); } return false; } }); button.setBounds(10, 10, 170, 170); stage.addActor(button); style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("tommie_button_green")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("tommie_button_red")); final Button speedButton = new Button(style); speedButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (glow.isActive()) { glow.disable(); } if (Math.abs(progressSpeed) == 10.0) { progressSpeed /= 5; } else { progressSpeed *= 5; } return false; } }); speedButton.setBounds(805, 40, 70, 70); stage.addActor(speedButton); logic = new Logic() { @Override public void render() { world.setDelta(Gdx.graphics.getDeltaTime()); world.process(); tweenManager.update(world.getDelta()); stage.draw(); stage.act(world.getDelta()); if (progressing) { Progress.setProgress(Progress.getProgress() + progressSpeed * world.getDelta()); if (progressSpeed > 0 && Progress.getProgress() > 4) { button.setTouchable(Touchable.enabled); button.setChecked(false); progressing = false; } else if (progressSpeed < 0 && Progress.getProgress() < 1) { button.setTouchable(Touchable.enabled); button.setChecked(false); progressing = false; } if (!progressing && Math.abs(progressSpeed) == 10.0) { --health; if (health <= 0 && progressSpeed > 0) { Progress.setProgress(Progress.getProgress() + 1); blowUp(); button.setTouchable(Touchable.disabled); button.setChecked(true); won = true; Label label = new Label("Tommie has been defeated!", labelStyle); stage.addActor(label); movingLabel(label); SoundEffectsManager.explode(); } } } if (won) { timer += world.getDelta(); if (timer > 5) { level = 2; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); // disposeSystems(world); } } } }; Label label = new Label("Meet the evil Tommie", labelStyle); stage.addActor(label); movingLabel(label); } else if (level == 2) { world.setSystem(new PeopleSystem()); world.setSystem(new SpriteRenderSystem()); world.setSystem(new EffectSystem()); world.setSystem(new LightSystem()); world.setSystem(new PhysicsSystem(box2dWorld)); world.initialize(); EntityCreator.createScene(world).addToWorld(); EntityCreator.createJezper(world).addToWorld(); EntityCreator.createPeople1(world).addToWorld(); EntityCreator.createPeople2(world).addToWorld(); EntityCreator.createPeople3(world).addToWorld(); EntityCreator.createLight1(world).addToWorld(); EntityCreator.createLight2(world).addToWorld(); EntityCreator.createLight3(world).addToWorld(); EntityCreator.createWorld(box2dWorld); EntityCreator.createBall(world, box2dWorld, 15, 60).addToWorld(); EntityCreator.createBall(world, box2dWorld, 50, 75).addToWorld(); EntityCreator.createBall(world, box2dWorld, 100, 80).addToWorld(); EntityCreator.createBall(world, box2dWorld, 150, 75).addToWorld(); timer = 0; won = false; health = 0; Progress.setProgress(0); final Song song = new Song(MusicManager.getSong(MusicManager.JEZPER)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("button")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("button_pressed")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); EntityCreator.createFire(world, 90, 40).addToWorld(); EntityCreator.createFire(world, 60, 40).addToWorld(); won = true; timer = 0; SoundEffectsManager.explode(); Label label = new Label("Jezper has been defeated!", labelStyle); stage.addActor(label); movingLabel(label); Iterator<Body> bodies = box2dWorld.getBodies(); while (bodies.hasNext()) { Body body = bodies.next(); if (body.getUserData() instanceof Entity) { List<JointEdge> joints = body.getJointList(); for (int i = 0; i < joints.size(); ++i) { box2dWorld.destroyJoint(joints.get(0).joint); } } } box2dWorld.setContactListener(new ContactListener() { @Override public void beginContact(Contact contact) { if (health < 10) { Vector2 p = contact.getFixtureA().getBody().getPosition(); Body a = contact.getFixtureA().getBody(); Body b = contact.getFixtureB().getBody(); Body body = null; if (a.getUserData() instanceof Entity) { body = a; } if (b.getUserData() instanceof Entity) { // Entity B collided with wall if (body == null) { p = b.getPosition(); EntityCreator.createFire(world, p.x * 10, p.y * 10).addToWorld(); // A collided with B } else { EntityCreator .createFire(world, (a.getPosition().x + b.getPosition().x) * 10 / 2, (a.getPosition().y + b.getPosition().y) * 10 / 2) .addToWorld(); } } else { // A collided with wall p = a.getPosition(); EntityCreator.createFire(world, p.x * 10, p.y * 10).addToWorld(); } SoundEffectsManager.explode(); ++health; } } @Override public void endContact(Contact contact) { } @Override public void preSolve(Contact contact, Manifold oldManifold) { } @Override public void postSolve(Contact contact, ContactImpulse impulse) { } }); return false; } }); button.setBounds(10, 10, 170, 170); button.setTouchable(Touchable.disabled); button.setChecked(true); stage.addActor(button); Label label = new Label("Meet the evil Jezper", labelStyle); stage.addActor(label); movingLabel(label); logic = new Logic() { @Override public void render() { world.setDelta(Gdx.graphics.getDeltaTime()); world.process(); tweenManager.update(world.getDelta()); stage.draw(); stage.act(world.getDelta()); timer += world.getDelta(); if (won) { if (timer > 8) { level = 3; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); // disposeSystems(world); } } else { // wait 3 seconds until enabling the button Progress.setProgress(Progress.getProgress() + world.getDelta()); if (timer > 3 && button.getTouchable() == Touchable.disabled) { button.setTouchable(Touchable.enabled); button.setChecked(false); } } } }; } else if (level == 3) { final LabelStyle creditsLabelStyle = new LabelStyle(); creditsLabelStyle.font = FontManager.getCreditsFont(); creditsLabelStyle.fontColor = new Color(0, 0, 0, 1); final Label label = new Label( "Congratulations! You have defeated the Slashat crew!\nThe people of earth have been saved and can once again\nlive in peace and harmony\n\n\n\nCredits\n\nMade by, programming & graphics:\n Daniel \"MaTachi\" Jonsson, http://danielj.se\n\nJava libraries:\n LibGDX, Artemis & Tween Engine\nSoftware used:\n Eclipse, GIMP & Aseprite on Ubuntu\nFonts:\n Rase GPL & EptKazoo\nMusic:\n Theme Music by Alexandr Zhelanov\n Dissonant Waltz by Yubatake\n Below The Shift by Clearside\nSound effect:\n Explode by Michel Baradari\n\n\nThanks Slashat for all years of podcast!\n\n\nDisclaimer: This game is just something silly and shouldn't\nbe taken seriously. I have no connection with Slashat\nother than being a fan and a longtime listener. :)\nIf I had had more time I would have made levels for\nMagnus and Johan too.", creditsLabelStyle); stage.addActor(label); Song song = new Song(MusicManager.getSong(MusicManager.THEME)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 2f).target(1.0f).ease(Quart.INOUT)) .start(tweenManager); logic = new Logic() { float timer = 0; @Override public void render() { timer += Gdx.graphics.getDeltaTime(); label.setPosition(20, 40 * timer - 1540); tweenManager.update(Gdx.graphics.getDeltaTime()); stage.draw(); stage.act(world.getDelta()); } }; } }
From source file:service.InputGame.java
License:Open Source License
/** * Singleton pattern.//from w ww. j a v a 2 s . co m * * @return a unique instance of InputMultiplexer. */ public static InputMultiplexer getInputMultiplexer() { if (obj == null) { obj = new InputMultiplexer(); } return obj; }
From source file:seventh.client.SeventhGame.java
License:Open Source License
/** * @param config//from ww w.ja v a2 s . c o m */ public SeventhGame(ClientSeventhConfig config) throws Exception { this.console = Cons.getImpl(); this.timeStep = new TimeStep(); this.terminal = new Terminal(console, config); this.inputs = new InputMultiplexer(); Cons.println(HEADER); Cons.println("*** Initializing " + VERSION + " ***"); Cons.println("Start Stamp: " + new Date()); this.config = config; this.keyMap = config.getKeyMap(); this.connection = new ClientConnection(this, config, console); this.screenStack = new Stack<Screen>(); this.sm = new StateMachine<Screen>(); this.theme = new Theme(); setupCommand(Cons.getImpl()); // Can't set this up here because the // Gdx context hasn't been created yet // this.menuScreen = new MenuScreen(this); }