List of usage examples for com.badlogic.gdx InputMultiplexer addProcessor
public void addProcessor(InputProcessor processor)
From source file:de.gebatzens.meteva.GScout.java
License:Open Source License
@Override public void create() { //For testing trace = false;/*from w w w . j av a2 s .c om*/ if (trace) tracei.beginTrace("initmeteva"); batch = new SpriteBatch(); atlas = new TextureAtlas(Gdx.files.internal("all.pack")); sbg = new SpaceBackground(); sbg.initBackground(); settings = new Settings(); settings.load(); highscoren = new Highscore(); highscoren.load(false); highscoref = new Highscore(); highscoref.load(true); mprof = new MarketProfile(); mprof.load(); mprof.reset(); Gdx.app.setLogLevel(Application.LOG_ERROR); manager = new AssetManager(); locale = Locale.getDefault(); bundle = I18NBundle.createBundle(Gdx.files.internal("lang/bundle"), locale); Gdx.app.debug("Meteva", "using locale " + locale); for (int i = 0; i < 4; i++) { meteorExpl[i] = Gdx.audio.newSound(Gdx.files.internal("sounds/expl" + (i + 1) + ".ogg")); } playerExpl = Gdx.audio.newSound(Gdx.files.internal("sounds/raumschiffexpl.ogg")); laser = Gdx.audio.newSound(Gdx.files.internal("sounds/laser.ogg")); rush = Gdx.audio.newMusic(Gdx.files.internal("sounds/rush.mp3")); rush.setLooping(true); if (settings.musicEnabled()) rush.play(); Texture tex = new Texture(Gdx.files.internal("survivant.png")); tex.setFilter(TextureFilter.Linear, TextureFilter.Linear); survivant = new BitmapFont(Gdx.files.internal("survivant.fnt"), new TextureRegion(tex), false); fontShader = new ShaderProgram(Gdx.files.internal("font.vert"), Gdx.files.internal("font.frag")); if (!fontShader.isCompiled()) { Gdx.app.error("fontShader", "compilation failed:\n" + fontShader.getLog()); } Pixmap p = new Pixmap(1, 1, Format.RGBA8888); p.setColor(Color.WHITE); p.drawPixel(0, 0); whiteTexture = new Texture(p); p.dispose(); // camera = new OrthographicCamera(1920, 1080); // camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // camera.setToOrtho(true); InputMultiplexer im = new InputMultiplexer(); im.addProcessor(this); GestureDetector gd = new GestureDetector(this); im.addProcessor(gd); Gdx.input.setInputProcessor(im); width = Gdx.graphics.getWidth(); height = Gdx.graphics.getHeight(); musicb = new SoundButton(GScout.width * 0.022f, GScout.height * 0.02f, GScout.getRegion("ton"), GScout.getRegion("tonaus"), GScout.width * 0.065f); musicb.activated = !settings.musicEnabled(); soundb = new SoundButton(GScout.width * 0.022f + 0.07f * GScout.width, GScout.height * 0.02f, GScout.getRegion("spielton"), GScout.getRegion("spieltonaus"), GScout.width * 0.065f); soundb.activated = !settings.soundsEnabled(); state = new MainState(); state.init(); if (trace) tracei.endTrace(); }
From source file:edu.lehigh.cse.lol.Level.java
License:Open Source License
/** * Construct a level. This is mostly using defaults, so the main work is in * camera setup//from w w w .j ava 2s. c o m * * @param width The width of the level, in meters * @param height The height of the level, in meters */ Level(int width, int height) { // clear any timers Timer.instance().clear(); // Set up listeners for touch events. Gestures are processed before // non-gesture touches, and non-gesture touches are only processed when // a gesture is not detected. InputMultiplexer mux = new InputMultiplexer(); mux.addProcessor(new GestureDetector(new LolGestureManager())); mux.addProcessor(new LolInputManager()); Gdx.input.setInputProcessor(mux); // reset the per-level object store mLevelFacts = new TreeMap<>(); mLevelActors = new TreeMap<>(); // save the camera bounds mCamBoundX = width; mCamBoundY = height; // warn on strange dimensions if (width < Lol.sGame.mWidth / Physics.PIXEL_METER_RATIO) Util.message("Warning", "Your game width is less than 1/10 of the screen width"); if (height < Lol.sGame.mHeight / Physics.PIXEL_METER_RATIO) Util.message("Warning", "Your game height is less than 1/10 of the screen height"); // set up the game camera, with 0,0 in the bottom left mGameCam = new OrthographicCamera(Lol.sGame.mWidth / Physics.PIXEL_METER_RATIO, Lol.sGame.mHeight / Physics.PIXEL_METER_RATIO); mGameCam.position.set(Lol.sGame.mWidth / Physics.PIXEL_METER_RATIO / 2, Lol.sGame.mHeight / Physics.PIXEL_METER_RATIO / 2, 0); mGameCam.zoom = 1; // set up the heads-up display camera int camWidth = Lol.sGame.mWidth; int camHeight = Lol.sGame.mHeight; mHudCam = new OrthographicCamera(camWidth, camHeight); mHudCam.position.set(camWidth / 2, camHeight / 2, 0); // the background camera is like the hudcam mBgCam = new ParallaxCamera(camWidth, camHeight); mBgCam.position.set(camWidth / 2, camHeight / 2, 0); mBgCam.zoom = 1; // set up the renderables for (int i = 0; i < 5; ++i) mRenderables.add(new ArrayList<Renderable>()); // set up the callback for finding out who in the physics world was // touched mTouchCallback = new QueryCallback() { @Override public boolean reportFixture(Fixture fixture) { // if the hit point is inside the fixture of the body we report // it if (fixture.testPoint(mTouchVec.x, mTouchVec.y)) { Actor hs = (Actor) fixture.getBody().getUserData(); if (hs.mVisible) { mHitActor = hs; return false; } } return true; } }; }
From source file:hku.fyp14017.blencode.stage.StageListener.java
License:Open Source License
@Override public void create() { font = new BitmapFont(); font.setColor(1f, 0f, 0.05f, 1f);/*w w w . j a v a 2 s.c o m*/ font.setScale(1.2f); project = ProjectManager.getInstance().getCurrentProject(); pathForScreenshot = Utils.buildProjectPath(project.getName()) + "/"; virtualWidth = project.getXmlHeader().virtualScreenWidth; virtualHeight = project.getXmlHeader().virtualScreenHeight; virtualWidthHalf = virtualWidth / 2; virtualHeightHalf = virtualHeight / 2; stage = new Stage(virtualWidth, virtualHeight, true); batch = stage.getSpriteBatch(); Gdx.gl.glViewport(0, 0, ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT); initScreenMode(); sprites = project.getSpriteList(); for (Sprite sprite : sprites) { sprite.resetSprite(); sprite.look.createBrightnessContrastShader(); stage.addActor(sprite.look); sprite.resume(); } passepartout = new Passepartout(ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT, maximizeViewPortWidth, maximizeViewPortHeight, virtualWidth, virtualHeight); stage.addActor(passepartout); 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); } axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp")); skipFirstFrameForAutomaticScreenshot = true; if (checkIfAutomaticScreenshotShouldBeTaken) { makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME); } }
From source file:net.ivang.axonix.main.AxonixGame.java
License:Apache License
@Inject private AxonixGame(InputMultiplexer inputMultiplexer, EventBus eventBus) { initSkin();// w w w.j av a 2s . com initLevels(); // Input event handling inputMultiplexer.addProcessor(new AxonixGameInputProcessor(eventBus)); Gdx.input.setInputProcessor(inputMultiplexer); // register with the event bus this.eventBus = eventBus; eventBus.register(this); }
From source file:net.mwplay.cocostudio.ui.DemoScreen.java
License:Apache License
@Override public void show() { super.show(); stage = new Stage(new StretchViewport(DemoGame.GAME_WIDTH, DemoGame.GAME_HEIGHT)); InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(stage); initDemoChange(multiplexer);/*from w w w . jav a 2s. com*/ Gdx.input.setInputProcessor(multiplexer); findAllDemos(); defaultFont = Gdx.files.internal("share/MLFZS.TTF"); changeDemo(); }
From source file:net.mwplay.cocostudio.ui.DemoScreen.java
License:Apache License
private void initDemoChange(InputMultiplexer multiplexer) { Stage demoChangeStage = new Stage(new StretchViewport(DemoGame.GAME_WIDTH, DemoGame.GAME_HEIGHT)); Actor actor = new Actor(); actor.setWidth(stage.getWidth());/*from ww w .jav a 2s .c o m*/ actor.setHeight(stage.getHeight()); actor.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { updateCurrentIndex(); changeDemo(); } }); demoChangeStage.addActor(actor); multiplexer.addProcessor(demoChangeStage); }
From source file:net.onedaybeard.keyflection.demo.DemoUI.java
License:Apache License
@Override public void create() { background = new Color(0.2f, 0.2f, 0.2f, 1f); texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); font = new BitmapFont(Gdx.files.internal("data/font.fnt"), false); stageActions = new StageKeys(); stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2; for (int i = 0; i < NUM_GROUPS; i++) { Group group = new Group(); group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING))); group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING))); group.setOrigin(loc, loc);//from w ww . j av a 2 s .c o m fillGroup(group, texture); stage.addActor(group); } uiTexture = new Texture(Gdx.files.internal("data/ui.png")); uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); ui = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); ui.addListener(new KeyflectionInputListener(stageActions)); Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32)); blend.setAlign(Align.center); blend.setScaling(Scaling.none); blend.addListener(new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { stageActions.toggleBlending(); return true; } }); blend.setY(ui.getHeight() - 64); Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32)); rotate.setAlign(Align.center); rotate.setScaling(Scaling.none); rotate.addListener(new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { stageActions.toggleRotation(); return true; } }); rotate.setPosition(64, blend.getY()); Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32)); scale.setAlign(Align.center); scale.setScaling(Scaling.none); scale.addListener(new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { stageActions.toggleScaling(); return true; } }); scale.setPosition(128, blend.getY()); ui.addActor(blend); ui.addActor(rotate); ui.addActor(scale); hint = new Label("Press F1 to see keyboard shortcuts.", new Label.LabelStyle(font, Color.WHITE)); hint.setPosition(10, 45); hint.setColor(0, 1, 0, 1); ui.addActor(hint); fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE)); fps.setPosition(10, 30); fps.setColor(0, 1, 0, 1); ui.addActor(fps); renderer = new ShapeRenderer(); InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(new KeyflectionInputProcessor(new GlobalKeys())); multiplexer.addProcessor(stage); multiplexer.addProcessor(ui); Gdx.input.setInputProcessor(multiplexer); }
From source file:org.ams.testapps.paintandphysics.FallingBoxes.java
License:Open Source License
@Override public void create() { Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(10, 10 * (h / w)); cameraNavigator = new CameraNavigator(camera); polygonBatch = new PrettyPolygonBatch(); world = new PPWorld(); bodyMover = new BodyMover(world.boxWorld, camera); InputMultiplexer inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(bodyMover); inputMultiplexer.addProcessor(cameraNavigator); Gdx.input.setInputProcessor(inputMultiplexer); texture = new Texture("images/for packing/backgrounds-light/giftly.png"); texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); addGround(texture);//from w w w . j a v a2 s . c o m }
From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java
License:Open Source License
/** * Use this to run the puzzle from another {@link ApplicationAdapter}. * <p/>/* w ww. j a v a2s .c o m*/ * Remember to dispose of the atlas when you no longer use it. * * @param inputMultiplexer InputProcessors will be added to the end of the multiplexer * @param textureRegion The region to draw on the puzzle. * @param def defines this particular game */ public void create(InputMultiplexer inputMultiplexer, TextureRegion textureRegion, PhysicsPuzzleDef def, Callback gameOverCallback) { if (textureRegion == null) throw new IllegalArgumentException("TextureRegion is null."); if (def == null) throw new IllegalArgumentException("PhysicsPuzzleDef is null."); this.gameOverCallback = gameOverCallback; // camera stuff float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(10, 10 * (h / w)); cameraNavigator = new CameraNavigator(camera); cameraNavigator.setActive(false); // physics world = new PPWorld(); bodyMover = new BodyMover(world.boxWorld, camera); // batches for drawing polygonBatch = new PrettyPolygonBatch(); shapeRenderer = new ShapeRenderer(); shapeRenderer.setAutoShapeType(true); // input multiplexing if (inputMultiplexer == null) { inputMultiplexer = new InputMultiplexer(); Gdx.input.setInputProcessor(inputMultiplexer); } this.inputMultiplexer = inputMultiplexer; inputMultiplexer.addProcessor(bodyMover); inputMultiplexer.addProcessor(cameraNavigator); initFromDefinition(textureRegion, def); lookAtPuzzle(); }
From source file:org.catrobat.catroid.stage.StageListener.java
License:Open Source License
@Override public void create() { font = new BitmapFont(); font.setColor(1f, 0f, 0.05f, 1f);/* ww w . j a va 2 s . c om*/ font.getData().setScale(1.2f); deltaActionTimeDivisor = 10f; shapeRenderer = new ShapeRenderer(); project = ProjectManager.getInstance().getCurrentProject(); scene = ProjectManager.getInstance().getSceneToPlay(); pathForSceneScreenshot = Utils.buildScenePath(project.getName(), scene.getName()) + "/"; virtualWidth = project.getXmlHeader().virtualScreenWidth; virtualHeight = project.getXmlHeader().virtualScreenHeight; virtualWidthHalf = virtualWidth / 2; virtualHeightHalf = virtualHeight / 2; camera = new OrthographicCamera(); viewPort = new ExtendViewport(virtualWidth, virtualHeight, camera); if (batch == null) { batch = new SpriteBatch(); } else { batch = new SpriteBatch(1000, batch.getShader()); } stage = new Stage(viewPort, batch); initScreenMode(); initStageInputListener(); physicsWorld = scene.resetPhysicsWorld(); clonedSprites = new HashSet<>(); sprites = new ArrayList<>(scene.getSpriteList()); boolean addPenActor = true; for (Sprite sprite : sprites) { sprite.resetSprite(); sprite.look.createBrightnessContrastHueShader(); stage.addActor(sprite.look); if (addPenActor) { penActor = new PenActor(); stage.addActor(penActor); addPenActor = false; } } passepartout = new Passepartout(ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT, maximizeViewPortWidth, maximizeViewPortHeight, virtualWidth, virtualHeight); stage.addActor(passepartout); 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); } axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp")); skipFirstFrameForAutomaticScreenshot = true; if (checkIfAutomaticScreenshotShouldBeTaken) { makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME) || scene.screenshotExists(SCREENSHOT_AUTOMATIC_FILE_NAME) || scene.screenshotExists(SCREENSHOT_MANUAL_FILE_NAME); } if (drawDebugCollisionPolygons) { collisionPolygonDebugRenderer.setProjectionMatrix(camera.combined); collisionPolygonDebugRenderer.setAutoShapeType(true); collisionPolygonDebugRenderer.setColor(Color.MAGENTA); } }