com.badlogic.gdx.Input类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中com.badlogic.gdx.Input类的一些代码示例,展示了Input类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Input类的具体详情如下:
包路径:com.badlogic.gdx.Input
类名称:Input

Input介绍

[英]Interface to the input facilities. This allows polling the state of the keyboard, the touch screen and the accelerometer. On some backends (desktop, gwt, etc) the touch screen is replaced by mouse input. The accelerometer is of course not available on all backends.

Instead of polling for events, one can process all input events with an InputProcessor. You can set the InputProcessor via the #setInputProcessor(InputProcessor) method. It will be called before the ApplicationListener#render()method in each frame.

Keyboard keys are translated to the constants in Keys transparently on all systems. Do not use system specific key constants.

The class also offers methods to use (and test for the presence of) other input systems like vibration, compass, on-screen keyboards, and cursor capture. Support for simple input dialogs is also provided.
[中]与输入设备的接口。这允许轮询键盘、触摸屏和加速计的状态。在某些后端(桌面、gwt等),触摸屏被鼠标输入取代。当然,加速计并非在所有后端都可用。
可以使用InputProcessor处理所有输入事件,而不是轮询事件。您可以通过#setInputProcessor(InputProcessor)方法设置InputProcessor。它将在每个帧中的ApplicationListener#render()方法之前调用。
在所有系统上,键盘键都透明地转换为键中的常量。不要使用系统特定的键常量。
该课程还提供了使用(和测试是否存在)其他输入系统的方法,如振动、指南针、屏幕键盘和光标捕捉。还提供了对简单输入对话框的支持。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
  public void create () {
// Gdx.input = new RemoteInput();
    Gdx.input.setInputProcessor(this);
// Gdx.input.setCursorCatched(true);
  }

代码示例来源:origin: libgdx/libgdx

static public boolean ctrl () {
  if (isMac)
    return Gdx.input.isKeyPressed(Keys.SYM);
  else
    return Gdx.input.isKeyPressed(Keys.CONTROL_LEFT) || Gdx.input.isKeyPressed(Keys.CONTROL_RIGHT);
}

代码示例来源:origin: libgdx/libgdx

@Override
public boolean isButtonPressed (int button) {
  return input.isButtonPressed(button);
}

代码示例来源:origin: libgdx/libgdx

private boolean isTouched (float startX, float endX) {
  // Check for touch inputs between startX and endX
  // startX/endX are given between 0 (left edge of the screen) and 1 (right edge of the screen)
  for (int i = 0; i < 2; i++) {
    float x = Gdx.input.getX(i) / (float)Gdx.graphics.getWidth();
    if (Gdx.input.isTouched(i) && (x >= startX && x <= endX)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: libgdx/libgdx

@Override
  public void render () {
    if (Gdx.input.justTouched()) {
      Gdx.app.log("Input Test", "just touched, button: " + (Gdx.input.isButtonPressed(Buttons.LEFT) ? "left " : "")
        + (Gdx.input.isButtonPressed(Buttons.MIDDLE) ? "middle " : "")
        + (Gdx.input.isButtonPressed(Buttons.RIGHT) ? "right" : "")
        + (Gdx.input.isButtonPressed(Buttons.BACK) ? "back" : "")
        + (Gdx.input.isButtonPressed(Buttons.FORWARD) ? "forward" : ""));
    }

    for (int i = 0; i < 10; i++) {
      if (Gdx.input.getDeltaX(i) != 0 || Gdx.input.getDeltaY(i) != 0) {
        Gdx.app.log("Input Test", "delta[" + i + "]: " + Gdx.input.getDeltaX(i) + ", " + Gdx.input.getDeltaY(i));
      }
    }
// Gdx.input.setCursorPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
// if(Gdx.input.isTouched()) {
// Gdx.app.log("Input Test", "is touched");
// }
  }

代码示例来源:origin: libgdx/libgdx

public RemoteSender (String ip, int port) {
  try {
    Socket socket = new Socket(ip, port);
    socket.setTcpNoDelay(true);
    socket.setSoTimeout(3000);
    out = new DataOutputStream(socket.getOutputStream());
    out.writeBoolean(Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen));
    connected = true;
    Gdx.input.setInputProcessor(this);
  } catch (Exception e) {
    Gdx.app.log("RemoteSender", "couldn't connect to " + ip + ":" + port);
  }
}

代码示例来源:origin: libgdx/libgdx

void triangulate () {
  // seed = 4139368480425561099l;
  // seed = 6559652580366669361l;
  MathUtils.random.setSeed(seed);
  int pointCount = 100;
  points.clear();
  for (int i = 0; i < pointCount; i++) {
    float value;
    do {
      value = MathUtils.random(10, 400);
    } while (points.contains(value));
    points.add(value);
    do {
      value = MathUtils.random(10, 400);
    } while (points.contains(value));
    points.add(value);
  }
  points.add(Gdx.input.getX());
  points.add(Gdx.graphics.getHeight() - Gdx.input.getY());
  triangles = trianglulator.computeTriangles(points, false);
}

代码示例来源:origin: libgdx/libgdx

@Override
public void render () {
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  camera.update();
  renderer.setProjectionMatrix(camera.combined);
  if (Gdx.input.isTouched()) camera.unproject(globalCoords.set(Gdx.input.getX(), Gdx.input.getY(), 0));
  solveFakeIK(globalCoords);
  renderBones();
}

代码示例来源:origin: libgdx/libgdx

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.begin(ShapeType.Filled);
if (Gdx.input.isTouched())
  renderer.setColor(Color.RED);
else
  renderer.setColor(Color.GREEN);
renderer.rect(Gdx.input.getX() - 15, Gdx.graphics.getHeight() - Gdx.input.getY() - 15, 30, 30);
renderer.rect(x, y, 30, 30);
renderer.end();
if (Gdx.input.isKeyPressed(Keys.ALT_LEFT)) {
  Gdx.app.log("GwtInputTest", "key pressed: " + "ALT_LEFT");
if (Gdx.input.isKeyPressed(Keys.CONTROL_LEFT)) {
  Gdx.app.log("GwtInputTest", "key pressed: " + "CTRL_LEFT");
if (Gdx.input.isKeyPressed(Keys.LEFT)) {
  x -= 1;
if (Gdx.input.isKeyPressed(Keys.RIGHT)) {
  x += 1;
if (Gdx.input.isKeyPressed(Keys.UP)) {
  y += 1;
if (Gdx.input.isKeyPressed(Keys.DOWN)) {
  y -= 1;

代码示例来源:origin: libgdx/libgdx

@Override
public void render () {
  currentPosition = music.getPosition();
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  batch.begin();
  batch.draw(buttons, 0, 0);
  font.draw(batch, (int)currentPosition / 60 + ":" + (int)currentPosition % 60, 365, 35);
  batch.end();
  sliderUpdating = true;
  slider.setValue((currentPosition / songDuration) * 100f);
  sliderUpdating = false;
  stage.act();
  stage.draw();
  if (Gdx.input.justTouched()) {
    if (Gdx.input.getY() > Gdx.graphics.getHeight() - 64) {
      if (Gdx.input.getX() < 64) {
        music.play();
      }
      if (Gdx.input.getX() > 64 && Gdx.input.getX() < 128) {
        music.stop();
      }
      if (Gdx.input.getX() > 128 && Gdx.input.getX() < 192) {
        music.pause();
      }
    }
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public void render () {
  Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  camera.update();
  renderer.setProjectionMatrix(camera.combined);
  renderer.begin(ShapeType.Filled);
  int size = Math.max(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()) / 10;
  for (int i = 0; i < 10; i++) {
    if (!Gdx.input.isTouched(i)) continue;
    viewport.unproject(tp.set(Gdx.input.getX(i), Gdx.input.getY(i)));
    Color color = colors[i % colors.length];
    renderer.setColor(color);
    float sSize = size * Gdx.input.getPressure(i);
    renderer.triangle(tp.x, tp.y + sSize, tp.x + sSize, tp.y - sSize, tp.x - sSize, tp.y - sSize);
  }
  renderer.end();
}

代码示例来源:origin: com.harium.etyl/etyl-gdx

protected void init() {
  graphics = new GDXGraphics(w, h);
  graphics.setOrthographicCamera(orthoCamera);
  graphics.setProjectionMatrix(orthoCamera.combined);
  // Set default font
  FontLoader.getInstance().loadDefaultFont();
  graphics.setFont(FontLoader.getInstance().defaultFont());
  // Override Back Button Behavior
  // Without this, dispose and reload does not work well
  Gdx.input.setCatchBackKey(true);
  Gdx.input.setInputProcessor(this);
  initModules();
}

代码示例来源:origin: libgdx/libgdx

@Override
public int getX (int pointer) {
  return input.getX(pointer);
}

代码示例来源:origin: libgdx/libgdx

@Override
public void setCatchBackKey (boolean catchBack) {
  input.setCatchBackKey(catchBack);
}

代码示例来源:origin: libgdx/libgdx

@Override
public int getY (int pointer) {
  return input.getY(pointer);
}

代码示例来源:origin: libgdx/libgdx

@Override
public boolean isTouched () {
  return input.isTouched();
}

代码示例来源:origin: libgdx/libgdx

gestureStartTime = Gdx.input.getCurrentEventTime();
tracker.start(x, y, gestureStartTime);
if (Gdx.input.isTouched(1)) {

代码示例来源:origin: libgdx/libgdx

@Override
public void render () {
  // clear the screen, update the camera and make the sprite batch
  // use its matrices.
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  camera.update();
  batch.setProjectionMatrix(camera.combined);
  // render all the things, we render in a y-down
  // cartesian coordinate system
  batch.begin();
  // drawing a region, x and y will be the top left corner of the region, would be bottom left
  // with y-up.
  batch.draw(region, 20, 100);
  // drawing text, x and y will be the top left corner for text, same as with y-up
  font.draw(batch, "This is a test", 270, 100);
  // drawing regions from an atlas, x and y will be the top left corner.
  // you shouldn't call findRegion every frame, cache the result.
  batch.draw(atlas.findRegion("badlogicsmall"), 360, 100);
  // drawing a sprite created from an atlas, FIXME wut?! AtlasSprite#setPosition seems to be wrong
  sprite.setColor(Color.RED);
  sprite.draw(batch);
  // finally we draw our current touch/mouse coordinates
  font.draw(batch, Gdx.input.getX() + ", " + Gdx.input.getY(), 0, 0);
  batch.end();
  // tell the stage to act and draw itself
  stage.act(Gdx.graphics.getDeltaTime());
  stage.draw();
}

代码示例来源:origin: libgdx/libgdx

public void render () {
    // set the clear color and clear the screen.
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // draw the sprite
    batch.begin();
    batch.draw(texture, spritePosition.x, spritePosition.y);
    batch.end();

    // if a finger is down, set the sprite's x/y coordinate.
    if (Gdx.input.isTouched()) {
      // the unproject method takes a Vector3 in window coordinates (origin in
      // upper left corner, y-axis pointing down) and transforms it to world
      // coordinates.
      camera.unproject(spritePosition.set(Gdx.input.getX(), Gdx.input.getY(), 0));
    }
  }
}

代码示例来源:origin: libgdx/libgdx

public RemoteSender (String ip, int port) {
  try {
    Socket socket = new Socket(ip, port);
    socket.setTcpNoDelay(true);
    socket.setSoTimeout(3000);
    out = new DataOutputStream(socket.getOutputStream());
    out.writeBoolean(Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen));
    connected = true;
    Gdx.input.setInputProcessor(this);
  } catch (Exception e) {
    Gdx.app.log("RemoteSender", "couldn't connect to " + ip + ":" + port);
  }
}

相关文章