List of usage examples for com.badlogic.gdx InputMultiplexer addProcessor
public void addProcessor(InputProcessor processor)
From source file:at.tugraz.ist.catroid.stage.StageListener.java
License:Open Source License
public void create() { font = new BitmapFont(); font.setColor(1f, 0f, 0.05f, 1f);/* w w w . j a v a2 s . co m*/ font.setScale(1.2f); pathForScreenshot = Utils.buildProjectPath(ProjectManager.getInstance().getCurrentProject().getName()) + "/"; costumeComparator = new CostumeComparator(); project = ProjectManager.getInstance().getCurrentProject(); virtualWidth = project.virtualScreenWidth; virtualHeight = project.virtualScreenHeight; virtualWidthHalf = virtualWidth / 2; virtualHeightHalf = virtualHeight / 2; screenMode = ScreenModes.STRETCH; stage = new Stage(virtualWidth, virtualHeight, true); batch = stage.getSpriteBatch(); camera = (OrthographicCamera) stage.getCamera(); camera.position.set(0, 0, 0); sprites = project.getSpriteList(); for (Sprite sprite : sprites) { stage.addActor(sprite.costume); } if (DEBUG) { OrthoCamController camController = new OrthoCamController(camera); InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(camController); multiplexer.addProcessor(stage); Gdx.input.setInputProcessor(multiplexer); fpsLogger = new FPSLogger(); } else { Gdx.input.setInputProcessor(stage); } background = new Texture(Gdx.files.internal("stage/white_pixel.bmp")); axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp")); }
From source file:com.badlogic.gdx.tests.Box2DTestCollection.java
License:Apache License
@Override public void create() { if (this.app == null) { this.app = Gdx.app; Box2DTest test = tests[testIndex]; test.create();// w ww . j a va 2s. co m } InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(this); multiplexer.addProcessor(new GestureDetector(this)); Gdx.input.setInputProcessor(multiplexer); }
From source file:com.bladecoder.engine.ui.defaults.DefaultSceneScreen.java
License:Apache License
@Override public void show() { retrieveAssets(ui.getUIAtlas());/* ww w .j ava2 s . co m*/ stage = new Stage(viewport); stage.addActor(textManagerUI); stage.addActor(dialogUI); stage.addActor(inventoryButton); stage.addActor(menuButton); stage.addActor(inventoryUI); stage.addActor(pie); menuButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.MENU_SCREEN); } }); final InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(stage); multiplexer.addProcessor(inputProcessor); Gdx.input.setInputProcessor(multiplexer); if (World.getInstance().isDisposed()) { try { World.getInstance().load(); } catch (Exception e) { EngineLogger.error("ERROR LOADING GAME", e); dispose(); Gdx.app.exit(); } } World.getInstance().resume(); }
From source file:com.bladecoder.engine.ui.retro.RetroSceneScreen.java
License:Apache License
@Override public void show() { retrieveAssets(ui.getUIAtlas());/*w w w. ja v a 2 s.com*/ stage = new Stage(screenViewport); // stage.addActor(textManagerUI); stage.addActor(dialogUI); stage.addActor(menuButton); stage.addActor(verbUI); stage.addActor(pointer); menuButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.MENU_SCREEN); } }); worldViewportStage = new Stage(worldViewport); worldViewportStage.addActor(textManagerUI); final InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(stage); multiplexer.addProcessor(inputProcessor); Gdx.input.setInputProcessor(multiplexer); if (World.getInstance().isDisposed()) { try { World.getInstance().load(); } catch (Exception e) { EngineLogger.error("ERROR LOADING GAME", e); dispose(); Gdx.app.exit(); } } World.getInstance().resume(); }
From source file:com.exovum.test.animation.CreditsScreen.java
License:Creative Commons License
public CreditsScreen(final Game game, Screen parentScreen) { this.batch = new SpriteBatch(); this.game = game; this.parent = parentScreen; Gdx.app.log("CreditsScreen", "Creating CreditsScreen"); menuBackground = new Texture(Gdx.files.internal("beach-ocean-sea-bg/transparent-png/full_background.png")); stage = new Stage(new FitViewport(800, 480)); Gdx.input.setInputProcessor(stage);//from ww w . j ava2s . com skin = new Skin(Gdx.files.internal("uiskin.json")); mainTable = new Table(skin); //mainTable.defaults().expand().fill().padBottom(4f).padTop(4f); mainTable.setFillParent(true); baseTable = new Table(skin); baseTable.defaults().expand().fill().padBottom(10f).padTop(10f); Label myHeader = new Label("General", skin, "small-font"); myHeader.setColor(Color.FIREBRICK); myHeader.setAlignment(Align.center); Label myCredits = new Label("Programming and Development\n" + "Caleb Stevenson", skin, "small-font"); myCredits.setColor(Color.BLACK); myCredits.setAlignment(Align.center); Label musicHeader = new Label("Music", skin, "small-font"); musicHeader.setColor(Color.FIREBRICK); musicHeader.setAlignment(Align.center); Label musicCredits = new Label("\"Capre Diem\", \"Hidden Past\", \"Pixel Peeker Polka - slower\"\n" + "Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0\n" + "http://creativecommons.org/licenses/by/3.0/", skin, "small-font"); musicCredits.setColor(Color.BLACK); musicCredits.setAlignment(Align.center); Label artHeader = new Label("Artwork", skin, "small-font"); artHeader.setColor(Color.FIREBRICK); artHeader.setAlignment(Align.center); Label artCredits = new Label("Background and Tree Sprites\n" + "http://bevouliin.com\nopengameart.org", skin, "small-font"); artCredits.setColor(Color.BLACK); artCredits.setAlignment(Align.center); TextButton exitButton = new TextButton("Back to Menu", skin, "small-font"); Table buttonTable = new Table(skin); baseTable.add(myHeader).row(); baseTable.add(myCredits).row(); baseTable.add(musicHeader).row(); baseTable.add(musicCredits).row(); baseTable.add(artHeader).row(); baseTable.add(artCredits).row(); baseTable.add(buttonTable); //menuTable.setBackground("console2"); // Set the color of the BACKGROUND on the buttons Color buttonColor = Color.SKY; exitButton.setColor(buttonColor); // Set the color of the TEXT on the buttons exitButton.getLabel().setColor(new Color(0.91f, 0.91f, 0.91f, 1)); buttonTable.defaults().expand().fill().padBottom(4f).padTop(2f); buttonTable.add(exitButton).width(180f).height(60f); //buttonTable.padTop(20f).padBottom(20f); buttonTable.left(); // Add baseTable containing buttonTable to the next row of mainTable //mainTable.add(buttonTable); mainTable.add(baseTable); // Add mainTable to the stage stage.addActor(mainTable); exitButton.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { Gdx.app.log("CreditsScreen", "Exiting to main menu"); //game.setScreen(new AnimatorMenuScreen(game)); //game.setScreen(parent); //((Game) Gdx.app.getApplicationListener()).setScreen(parent); ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game)); } }); //Use an InputMultiplexer so that the Stage and keyDown input processors can both be used InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(stage); multiplexer.addProcessor(new InputAdapter() { // If the back key is pressed, go to main menu // This also handles the Android 'back' button @Override public boolean keyDown(int keycode) { if (keycode == Input.Keys.BACK) { // Handle the back button Gdx.app.log("CreditsScreen", "KeyDown: BACK pressed"); //AnimatorMenuScreen newMenu = new AnimatorMenuScreen(batch, game); //game.setScreen(newMenu); //game.setScreen(parent); //((Game) Gdx.app.getApplicationListener()).setScreen(parent); ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game)); return true; } return false; } }); Gdx.input.setInputProcessor(multiplexer); }
From source file:com.qualcomm.vuforia.samples.libGDX.screens.ChooseBallScreen.java
License:Apache License
@Override public void create() { if (app.createServerScreen.create != null) { app.createServerScreen.create.resetUserChoiceState(); app.createServerScreen.create.startBallsDistribute(); } else if (app.joinServerScreen.join != null) { PropertiesSingleton.getInstance() .initRandomCoinPosition(PropertiesSingleton.getInstance().getChosenIsland()); //PropertiesSingleton.getInstance().initRandomPowerupPosition(PropertiesSingleton.getInstance().getChosenIsland()); }//w w w. j ava2 s.c o m modelBatch = new ModelBatch(); fps = new FPSLogger(); Gdx.app.log("height: " + Gdx.graphics.getHeight() + "", "width: " + Gdx.graphics.getWidth() + ""); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f)); environment.shadowMap = shadowLight; shadowBatch = new ModelBatch(new DepthShaderProvider()); cam = new VuforiaCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.near = 0.1f; cam.far = 300f; cam.update(); instances = new Array<ModelInstance>(); // instances.add(new ModelInstance(model, "floor")); // instances.add(ball = new Ball(model, "ball")); // ball.setPosition(1f, 1f, 1f); this.stage = new Stage(new StretchViewport(Gdx.graphics.getHeight(), Gdx.graphics.getHeight())); initFonts(); // BitmapFont font = new BitmapFont(); Label.LabelStyle labelStyle = new Label.LabelStyle(app.font60, Color.WHITE); Label.LabelStyle labelStyle2 = new Label.LabelStyle(app.font60, Color.WHITE); Label labelTitle = new Label("CHOOSE BALL ", labelStyle); LabelScore = new Label("apple", labelStyle2); // labelTitle.setScale(Gdx.graphics.getWidth() / 10, Gdx.graphics.getHeight() / 10); Gdx.app.log("width: " + Gdx.graphics.getWidth(), "height: " + Gdx.graphics.getHeight()); labelTitle.setPosition(Gdx.graphics.getHeight() / 2 - labelTitle.getWidth() / 2, Gdx.graphics.getHeight() - labelTitle.getHeight() * 2); LabelScore.setPosition(Gdx.graphics.getHeight() - (LabelScore.getWidth() + Gdx.graphics.getHeight() / 50), LabelScore.getHeight() / 2); swipe = new Image(new Sprite(new Texture(Gdx.files.internal("swipe2.png")))); swipe.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1))); // swipe.setSize((stage.getWidth()) / 6, stage.getHeight() / 6); swipe.setPosition(Gdx.graphics.getHeight() / 2 - swipe.getWidth() / 2, Gdx.graphics.getHeight() / 2 - swipe.getHeight() / 2); stage.addActor(swipe); accept = new Image(new Sprite(new Texture(Gdx.files.internal("accept.png")))); // accept.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1))); accept.setSize((stage.getWidth()) / 10, stage.getWidth() / 10); accept.setPosition(Gdx.graphics.getHeight() / 2 - accept.getWidth() / 2, accept.getHeight()); // stage.addActor(accept); stage.addActor(LabelScore); stage.addActor(labelTitle); TextureAtlas atlasVote = new TextureAtlas("Buttons.pack"); Skin voteSkin = new Skin(atlasVote); ImageButton.ImageButtonStyle voteButtonStyle = new ImageButton.ImageButtonStyle(); //Instaciate voteButtonStyle.up = voteSkin.getDrawable("ready"); //Set image for not pressed button voteButtonStyle.checked = voteSkin.getDrawable("notready"); //Set image for not pressed button readyButton = new ImageButton(voteButtonStyle); readyButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (app.joinServerScreen.join != null) { app.joinServerScreen.join.sendBallChoice(ballNames.get(currentBall)); } else if (app.createServerScreen.create != null) { app.createServerScreen.create.serverUser.setBallChoice(ballNames.get(currentBall)); app.createServerScreen.create.serverUser.setChosen(true); app.createServerScreen.create.notifyBalls(); } } }); readyButton.setSize((stage.getWidth()) / 5, stage.getWidth() / 10); readyButton.setPosition(Gdx.graphics.getHeight() / 2 - readyButton.getWidth() / 2, 0); stage.addActor(readyButton); for (int i = 0; i < ballNames.size; i++) { Model tmpModel = assets.get("3d/balls/" + ballNames.get(i) + ".g3db", Model.class); for (int k = 0; k < tmpModel.meshes.size; k++) tmpModel.meshes.get(k).scale(5, 5, 5); // String id = tmpModel.nodes.get(0).id; // Node node = tmpModel.getNode(id); // node.scale.set(30f, 30f, 30f); // node.translation.set(0, 15f, 0); // tmpModel.calculateTransforms(); instances.add(new ModelInstance(tmpModel)); } InputMultiplexer inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(stage); inputMultiplexer.addProcessor(new GestureDetector(0.0f, 0.0f, 0.0f, 5f, this)); Gdx.input.setInputProcessor(inputMultiplexer); }
From source file:com.qualcomm.vuforia.samples.libGDX.screens.ChooseIslandScreen.java
License:Apache License
@Override public void create() { if (app.createServerScreen.create != null) { app.createServerScreen.create.resetUserChoiceState(); app.createServerScreen.create.startIslandVote(); }//from w ww .j a va 2 s . com modelBatch = new ModelBatch(); fps = new FPSLogger(); Gdx.app.log("height: " + Gdx.graphics.getHeight() + "", "width: " + Gdx.graphics.getWidth() + ""); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f)); // environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); // environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f, // -.2f)); // environment.shadowMap = shadowLight; shadowBatch = new ModelBatch(new DepthShaderProvider()); cam = new VuforiaCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.near = 0.1f; cam.far = 300f; cam.update(); instances = new Array<ModelInstance>(); voteButtons = new Array<ImageButton>(); this.stage = new Stage(new StretchViewport(Gdx.graphics.getHeight(), Gdx.graphics.getHeight())); initFonts(); // BitmapFont font = new BitmapFont(); Label.LabelStyle labelStyle = new Label.LabelStyle(app.font60, Color.WHITE); Label.LabelStyle labelStyle2 = new Label.LabelStyle(app.font60, Color.WHITE); Label labelTitle = new Label("CHOOSE ISLAND ", labelStyle); LabelScore = new Label("forest", labelStyle2); // labelTitle.setScale(Gdx.graphics.getWidth() / 10, Gdx.graphics.getHeight() / 10); Gdx.app.log("width: " + Gdx.graphics.getWidth(), "height: " + Gdx.graphics.getHeight()); labelTitle.setPosition(Gdx.graphics.getHeight() / 2 - labelTitle.getWidth() / 2, Gdx.graphics.getHeight() - labelTitle.getHeight() * 2); LabelScore.setPosition(Gdx.graphics.getHeight() - (LabelScore.getWidth() + Gdx.graphics.getHeight() / 50), LabelScore.getHeight() / 2); swipe = new Image(new Sprite(new Texture(Gdx.files.internal("swipe2.png")))); swipe.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1))); // swipe.setSize((stage.getWidth()) / 6, stage.getHeight() / 6); swipe.setPosition(Gdx.graphics.getHeight() / 2 - swipe.getWidth() / 2, Gdx.graphics.getHeight() / 2 - swipe.getHeight() / 2); stage.addActor(swipe); accept = new Image(new Sprite(new Texture(Gdx.files.internal("accept.png")))); accept.setSize((stage.getWidth()) / 10, stage.getWidth() / 10); accept.setPosition(Gdx.graphics.getHeight() / 2 - accept.getWidth() / 2, accept.getHeight()); stage.addActor(LabelScore); stage.addActor(labelTitle); TextureAtlas atlasVote = new TextureAtlas("Buttons.pack"); Skin voteSkin = new Skin(atlasVote); ImageButton.ImageButtonStyle voteButtonStyle = new ImageButton.ImageButtonStyle(); //Instaciate voteButtonStyle.up = voteSkin.getDrawable("notvoted"); //Set image for not pressed button voteButtonStyle.checked = voteSkin.getDrawable("voted"); //Set image for pressed for (int i = 0; i < islandNames.size; i++) { Model tmpModel = assets.get("3d/islands/" + islandNames.get(i) + ".g3db", Model.class); // tmpModel.meshes.get(0).scale(3,3,3); // Texture texture2 = new Texture(Gdx.files.internal("3d/islands/"+islandNames.get(i)+".jpg"), Pixmap.Format.RGB888, false); // TextureAttribute textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture2); // Material material = tmpModel.materials.get(0); // material.set(textureAttribute); instances.add(new ModelInstance(tmpModel)); } int numberOfIslands = islandNames.size; for (int i = 0; i < numberOfIslands; i++) { ImageButton item1Button = new ImageButton(voteButtonStyle); item1Button.setSize((stage.getWidth()) / 10, stage.getWidth() / 6); // Gdx.input.setInputProcessor(stage); item1Button.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { voted = islandNames.get(currentIsland); if (app.joinServerScreen.join != null) { app.joinServerScreen.join.sendIslandChoice(voted); } else if (app.createServerScreen != null) { app.createServerScreen.create.serverUser.setIslandChoice(voted); app.createServerScreen.create.serverUser.setChosen(true); app.createServerScreen.create.notifyIsland(); } //boolean found = false; /*for(int k = 0; k < voted.size; k++) { if(voted.get(k) == islandNames.get(currentIsland)) found = true; } if(!found) voted.add(islandNames.get(currentIsland)); Gdx.app.log("voted", voted + ""); PropertiesSingleton.getInstance().setChoosenIsland(islandNames.get(currentIsland));*/ //app.setScreen(new ChooseBallScreen(app)); } }); item1Button.setPosition(0, -item1Button.getHeight()); voteButtons.add(item1Button); stage.addActor(voteButtons.get(i)); } voteButtons.get(currentIsland).setPosition(Gdx.graphics.getHeight() / 2 - accept.getWidth() / 2, accept.getHeight()); InputMultiplexer inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(stage); inputMultiplexer.addProcessor(new GestureDetector(0.0f, 0.0f, 0.0f, 5f, this)); Gdx.input.setInputProcessor(inputMultiplexer); }
From source file:com.ray3k.libraryinvaders.states.GameState.java
License:Open Source License
@Override public void start() { EnemyEntity.speedMultiplier = 1.0f;//from w ww . j a v a 2s. c o m respawnTimer = -1; score = 0; ufoTimer = UFO_MAX_TIME; inputManager = new InputManager(); camera = new OrthographicCamera(); viewport = new ScreenViewport(camera); viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); viewport.apply(); camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0); skin = getCore().getAssetManager().get(Core.DATA_PATH + "/skin/skin.json", Skin.class); stage = new Stage(new ScreenViewport()); InputMultiplexer inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(inputManager); inputMultiplexer.addProcessor(stage); Gdx.input.setInputProcessor(inputMultiplexer); table = new Table(); table.setFillParent(true); stage.addActor(table); entityManager = new EntityManager(); PlayerEntity player = new PlayerEntity(this); spawnEntities(); Array<BarricadeEntity> barricades = new Array<BarricadeEntity>(); float barricadesWidth = 0.0f; final int BARRICADE_COUNT = 4; for (int i = 0; i < BARRICADE_COUNT; i++) { BarricadeEntity barricade = new BarricadeEntity(this); Array<String> names = getCore().getImagePacks().get(Core.DATA_PATH + "/barricades"); barricade.setTextureRegion(getCore().getAtlas().findRegion(names.random())); barricade.setX(barricadesWidth); barricade.setY(30.0f + player.getTextureRegion().getRegionHeight() + 35.0f); barricadesWidth += barricade.getTextureRegion().getRegionWidth(); barricades.add(barricade); } final float GAP = (Gdx.graphics.getWidth() - barricadesWidth - 100.0f) / (BARRICADE_COUNT - 1); for (int i = 1; i < barricades.size; i++) { BarricadeEntity barricade = barricades.get(i); barricade.addX(GAP * i); barricadesWidth += GAP; } final float addX = (Gdx.graphics.getWidth() - barricadesWidth) / 2.0f; for (BarricadeEntity barricade : barricades) { barricade.addX(addX); subdivideBarricade(barricade); } createStageElements(); }
From source file:com.theosirian.ppioo.controllers.Controller.java
License:Open Source License
public void start() { InputMultiplexer inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(game.stage); inputMultiplexer.addProcessor(this); createComponents();//from w ww . ja v a2 s . c om Gdx.input.setInputProcessor(inputMultiplexer); game.stage.addActor(rootLayout); buildUI(); }
From source file:com.thetruthbeyond.botmaker.BotMaker.java
License:Open Source License
@Override public void create() { try {/*from w w w.j av a 2s .c o m*/ loader = new AssetsLoader(); loader.initialize(); Coding.configureCharsets(loader); Fonts.configureFonts(loader); Keyboard.getInstance().setFilter(Coding.signs); InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(cursor); multiplexer.addProcessor(keyboard); Gdx.input.setInputProcessor(multiplexer); } catch (Exception exception) { Logger logger = new Logger(); logger.writeMessage("Error occured", "Cause was detected in create() method of BotMaker class."); logger.writeError(exception); } try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ignored) { // If look and feel could not be found use the default one and do not report a mistake. } }