コード例 #1
0
  @Override
  public void create() {
    final float w = Gdx.graphics.getWidth();
    final float h = Gdx.graphics.getHeight();
    // create the camera and the SpriteBatch
    camera = new OrthographicCamera();
    camera.setToOrtho(false, w, h);

    viewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, camera);

    batch = new SpriteBatch();

    img = new Texture(Gdx.files.internal("playerSprite_1.png"));

    // create a new sprite based on our image
    sprite = new Sprite(img);

    sprite.setPosition(ScreenWidth / 2 - playerWidth, ScreenHeight / 2 - playerHeight);
    tiledMap = new TmxMapLoader().load("ritualsite.tmx");
    tiledMapRenderer = new OrthogonalTiledMapRendererWithSprites(tiledMap);
    tiledMapRenderer.addSprite(sprite);

    Gdx.input.setInputProcessor(this);
    targetPos = new Vector2(sprite.getX(), sprite.getY());

    // create a sprite batch
    batch = new SpriteBatch();

    direction = new Vector2();
    playerDirection = new Vector2();
    getCollidingRects();
  }
コード例 #2
0
  @Override
  public void render() {
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // tell the camera to update its matrices.

    updateCamera();

    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render();

    if (Gdx.input.isTouched()) {
      final Vector3 touchPos = new Vector3();
      touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
      camera.unproject(touchPos);
      targetPos.x = touchPos.x - sprite.getWidth() / 2;
      targetPos.y = touchPos.y - sprite.getHeight() / 2;
    }

    updateTargetPosition();
  }