com.badlogic.gdx.Graphics.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(125)

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

Graphics.getWidth介绍

暂无

代码示例

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

public void update (float deltaTime) {
    stateTime += deltaTime;
    pos.x = pos.x + (headsLeft ? -VELOCITY * deltaTime : VELOCITY * deltaTime);
    if (pos.x < -64) pos.x = Gdx.graphics.getWidth();
    if (pos.x > Gdx.graphics.getWidth() + 64) pos.x = -64;
  }
}

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

/**
 * Converts an x-coordinate given in logical screen coordinates to
 * backbuffer coordinates.
 */
public static int toBackBufferX(int logicalX) {
  return (int)(logicalX * Gdx.graphics.getBackBufferWidth() / (float)Gdx.graphics.getWidth());
}

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

@Override
  public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) {
    shader.set(inputID, (float)Gdx.graphics.getWidth());
  }
};

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

/**
 * Converts an x-coordinate given in backbuffer coordinates to
 * logical screen coordinates.
 */
public static int toLogicalX(int backBufferX) {
  return (int)(backBufferX * Gdx.graphics.getWidth() / (float)Gdx.graphics.getBackBufferWidth());
}

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

/** Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject but does not
 * rely on OpenGL. The viewport is assumed to span the whole screen and is fetched from {@link Graphics#getWidth()} and
 * {@link Graphics#getHeight()}. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left
 * corner, y pointing down, x pointing to the right) as reported by the touch methods in {@link Input}. A z-coordinate of 0
 * will return a point on the near plane, a z-coordinate of 1 will return a point on the far plane.
 * @param screenCoords the point in screen coordinates
 * @return the mutated and unprojected screenCoords {@link Vector3} */
public Vector3 unproject (Vector3 screenCoords) {
  unproject(screenCoords, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  return screenCoords;
}

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

@Override
  public void resize (int width, int height) {
    float ratio = ((float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight());
    int h = 10;
    int w = (int)(h * ratio);
    camera = new OrthographicCamera(w, h);
  }
}

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

/** Sets this camera to an orthographic projection using a viewport fitting the screen resolution, centered at
 * (Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2), with the y-axis pointing up or down.
 * @param yDown whether y should be pointing down */
public void setToOrtho (boolean yDown) {
  setToOrtho(yDown, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}

代码示例来源: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 boolean zoom (float initialDistance, float distance) {
  float newZoom = distance - initialDistance;
  float amount = newZoom - previousZoom;
  previousZoom = newZoom;
  float w = Gdx.graphics.getWidth(), h = Gdx.graphics.getHeight();
  return controller.pinchZoom(amount / ((w > h) ? h : w));
}

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

/** Calculates a scissor rectangle using 0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight() as the viewport.
 * @see #calculateScissors(Camera, float, float, float, float, Matrix4, Rectangle, Rectangle) */
public static void calculateScissors (Camera camera, Matrix4 batchTransform, Rectangle area, Rectangle scissor) {
  calculateScissors(camera, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), batchTransform, area, scissor);
}

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

/** Creates a picking {@link Ray} from the coordinates given in screen coordinates. It is assumed that the viewport spans the
   * whole screen. The screen coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis
   * pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function.
   * @return the picking Ray. */
  public Ray getPickRay (float screenX, float screenY) {
    return getPickRay(screenX, screenY, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  }
}

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

@Override
  public void resize (int width, int height) {
    float ratio = ((float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight());
    int h = 10;
    int w = (int)(h * ratio);
    camera = new OrthographicCamera(w, h);
  }
}

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

/** Creates a stage with the specified viewport and batch. This can be used to avoid creating a new batch (which can be
 * somewhat slow) if multiple stages are used during an application's life time.
 * @param batch Will not be disposed if {@link #dispose()} is called, handle disposal yourself. */
public Stage (Viewport viewport, Batch batch) {
  if (viewport == null) throw new IllegalArgumentException("viewport cannot be null.");
  if (batch == null) throw new IllegalArgumentException("batch cannot be null.");
  this.viewport = viewport;
  this.batch = batch;
  root = new Group();
  root.setStage(this);
  viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
}

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

@Override
public boolean touchDragged (int screenX, int screenY, int pointer) {
  boolean result = super.touchDragged(screenX, screenY, pointer);
  if (result || this.button < 0) return result;
  final float deltaX = (screenX - startX) / Gdx.graphics.getWidth();
  final float deltaY = (startY - screenY) / Gdx.graphics.getHeight();
  startX = screenX;
  startY = screenY;
  return process(deltaX, deltaY, button);
}

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

public ShapeRenderer (int maxVertices, ShaderProgram defaultShader) {
  if (defaultShader == null) {
    renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0);
  } else {
    renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0, defaultShader);
  }
  projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  matrixDirty = true;
}

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

public ShapeRenderer (int maxVertices, ShaderProgram defaultShader) {
  if (defaultShader == null) {
    renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0);
  } else {
    renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0, defaultShader);
  }
  projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  matrixDirty = true;
}

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

@Override
public void render () {
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  batch.begin();
  batch.draw(texture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  batch.end();
  
  Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0,  0,  Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  int color = pixmap.getPixel(0, pixmap.getHeight() - 1);
  Gdx.app.log("AlphaTest", Integer.toHexString(color));
  pixmap.dispose();
}

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

@Override
public void render() {
  Gdx.gl.glClearColor(0, 0, 0, 1f);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  batch.begin();
  batch.draw(texture, 0, 0, Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f);
  batch.end();
}

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

public void create () {
  renderer = new ShapeRenderer();
  cam = new PerspectiveCamera(47, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  cam.position.set(0, 0, 2);
  cam.near = 0.1f;
  controller = new PerspectiveCamController(cam);
  Gdx.input.setInputProcessor(controller);
  batch = new SpriteBatch();
  font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}

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

@Override
public void create () {
  float aspect = Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight();
  camera = new OrthographicCamera(15 * aspect, 15);
  camera.update();
  renderer = new ShapeRenderer();
  renderer.setProjectionMatrix(camera.combined);
  bones = new Bone[] {new Bone("bone0", 0, 0, 0), new Bone("bone1", 0, 2, 2), new Bone("bone2", 0, 4, 2),
    new Bone("bone3", 0, 6, 2), new Bone("end", 0, 8, 2)};
  globalCoords.set(bones[0].position);
}

相关文章