com.badlogic.gdx.InputAdapter Java Examples

The following examples show how to use com.badlogic.gdx.InputAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AudioGdxSoundTest.java    From gdx-pd with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) 
{
	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	
	new LwjglApplication(new Game(){
		@Override
		public void create() {
			
			// play a pd patch
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/test.pd"));
			
			// and sounds at the same time
			final Sound snd = Gdx.audio.newSound(Gdx.files.classpath("shotgun.wav"));
			snd.play();
			Gdx.input.setInputProcessor(new InputAdapter(){
				@Override
				public boolean touchDown(int screenX, int screenY, int pointer, int button) {
					snd.play();
					return true;
				}
			});
			
		}}, config);
	
}
 
Example #2
Source File: SplashScreen.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
  Controllers.addListener(controllerListener = new ControllerAdapter() {
    @Override
    public boolean buttonDown(Controller controller, int buttonIndex) {
      return pressToContinue();
    }
  });
  Riiablo.input.addProcessor(inputProcessor = new InputAdapter() {
    @Override
    public boolean keyDown(int keycode) {
      if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE
          || keycode == Input.Keys.VOLUME_DOWN || keycode == Input.Keys.VOLUME_UP) {
        return true;
      }

      return pressToContinue();
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
      return pressToContinue();
    }
  });
  Riiablo.input.addProcessor(stage);
}
 
Example #3
Source File: Invaders.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void create () {
	Array<Controller> controllers = Controllers.getControllers();
	if (controllers.size > 0) {
		controller = controllers.first();
	}
	Controllers.addListener(controllerListener);

	setScreen(new MainMenu(this));
	music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/8.12.mp3", FileType.Internal));
	music.setLooping(true);
	music.play();
	Gdx.input.setInputProcessor(new InputAdapter() {
		@Override
		public boolean keyUp (int keycode) {
			if (keycode == Keys.ENTER && Gdx.app.getType() == ApplicationType.WebGL) {
				if (!Gdx.graphics.isFullscreen()) Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayModes()[0]);
			}
			return true;
		}
	});

	fps = new FPSLogger();
}
 
Example #4
Source File: MainMenuScreen.java    From libgdx-2d-tutorial with MIT License 5 votes vote down vote up
public MainMenuScreen (final SpaceGame game) {
	this.game = game;
	playButtonActive = new Texture("play_button_active.png");
	playButtonInactive = new Texture("play_button_inactive.png");
	exitButtonActive = new Texture("exit_button_active.png");
	exitButtonInactive = new Texture("exit_button_inactive.png");
	logo = new Texture("logo.png");
	
	game.scrollingBackground.setSpeedFixed(true);
	game.scrollingBackground.setSpeed(ScrollingBackground.DEFAULT_SPEED);
	
	final MainMenuScreen mainMenuScreen = this;
	
	Gdx.input.setInputProcessor(new InputAdapter() {
		
		@Override
		public boolean touchDown(int screenX, int screenY, int pointer, int button) {
			//Exit button
			int x = SpaceGame.WIDTH / 2 - EXIT_BUTTON_WIDTH / 2;
			if (game.cam.getInputInGameWorld().x < x + EXIT_BUTTON_WIDTH && game.cam.getInputInGameWorld().x > x && SpaceGame.HEIGHT - game.cam.getInputInGameWorld().y < EXIT_BUTTON_Y + EXIT_BUTTON_HEIGHT && SpaceGame.HEIGHT - game.cam.getInputInGameWorld().y > EXIT_BUTTON_Y) {
				mainMenuScreen.dispose();
				Gdx.app.exit();
			}
			
			//Play game button
			x = SpaceGame.WIDTH / 2 - PLAY_BUTTON_WIDTH / 2;
			if (game.cam.getInputInGameWorld().x < x + PLAY_BUTTON_WIDTH && game.cam.getInputInGameWorld().x > x && SpaceGame.HEIGHT - game.cam.getInputInGameWorld().y < PLAY_BUTTON_Y + PLAY_BUTTON_HEIGHT && SpaceGame.HEIGHT - game.cam.getInputInGameWorld().y > PLAY_BUTTON_Y) {
				mainMenuScreen.dispose();
				game.setScreen(new MainGameScreen(game));
			}
			
			return super.touchUp(screenX, screenY, pointer, button);
		}
		
	});
}
 
Example #5
Source File: BlankWaitKeyScreen.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
public BlankWaitKeyScreen() {
    Gdx.input.setInputProcessor(new InputAdapter() {
        @Override
        public boolean keyUp(int keycode) {
            if(active) {
                setDuration(0); // Force finish.
            }
            return true;
        }
    });
}
 
Example #6
Source File: InstructWaitKeyScreen.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
public InstructWaitKeyScreen(String instruction) {
    super(instruction);

    Gdx.input.setInputProcessor(new InputAdapter() {
        @Override
        public boolean keyUp(int keycode) {
            if (active) {
                setDuration(0); // Force finish.
            }
            return true;
        }
    });
}
 
Example #7
Source File: AudioGdxBakingTest.java    From gdx-pd with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) 
{
	if(args.length > 0 && "remote".equals(args[0])){
		PdConfiguration.remoteEnabled = true;
	}
	new LwjglApplication(new Game() {
		
		private PdAudioBakery bakery;
		private boolean backingComplete = false;
		
		@Override
		public void create() 
		{
			// we first load patch owning destination arrays.
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/runtime.pd"));
			
			// then we schedule baking of our complex patches.
			bakery = new PdAudioBakery();
			
			bakery.addTask(Gdx.files.local("resources/complex-sound.pd"), "baked-sound", 44100, 3);
			
			bakery.start(new BakingListener() {
				@Override
				public void progress(float percents) {
					Gdx.app.log("Baking", "backing progress : " + String.valueOf(percents));
				}
				
				@Override
				public void complete() {
					backingComplete = true;
				}
			});
			
			// finally we playback backed sound when user touch screen
			Gdx.input.setInputProcessor(new InputAdapter(){
				@Override
				public boolean touchDown(int screenX, int screenY, int pointer, int button) {
					if(backingComplete){
						Pd.audio.sendBang("play-backed");
					}
					return true;
				}
			});
			
		}
		@Override
		public void render() {
			if(backingComplete)
				Gdx.gl.glClearColor(0, 0, 0, 0);
			else
				Gdx.gl.glClearColor(1, 0, 0, 0);
			Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		}
	}, new LwjglApplicationConfiguration());
	
}
 
Example #8
Source File: CameraTool.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void create() {
  batch = new SpriteBatch();
  font = new BitmapFont();
  iso = new IsometricCamera();
  shapes = new ShapeRenderer();
  shapes.setAutoShapeType(true);
  center.set(shapes.getTransformMatrix()).translate(
      Gdx.graphics.getWidth()  / 2,
      Gdx.graphics.getHeight() / 2,
      0);
  idt.set(shapes.getProjectionMatrix());

  iso.setToOrtho(false);
  iso.offset(0, -Tile.SUBTILE_HEIGHT50);
  iso.set(0, 0);

  Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);

  Gdx.input.setInputProcessor(new InputAdapter() {
    @Override
    public boolean scrolled(int amount) {
      iso.zoom += (amount * 0.05);
      iso.zoom = MathUtils.clamp(iso.zoom, 0.05f, 2f);
      return super.scrolled(amount);
    }

    @Override
    public boolean keyDown(int keycode) {
      final float AMOUNT = 0.25f;
      switch (keycode) {
        case Keys.SPACE:
          iso.set(0, 0);
          break;

        case Keys.SHIFT_LEFT:
          if (Gdx.input.isTouched()) break;
          moveToCursor(AMOUNT);
          break;

        case Keys.W:
        case Keys.UP:
          iso.translate(0, -AMOUNT);
          break;

        case Keys.S:
        case Keys.DOWN:
          iso.translate(0,  AMOUNT);
          break;

        case Keys.A:
        case Keys.LEFT:
          iso.translate(-AMOUNT, 0);
          break;

        case Keys.D:
        case Keys.RIGHT:
          iso.translate( AMOUNT, 0);
          break;
      }
      return super.keyDown(keycode);
    }
  });
}