예제 #1
0
  @Override
  public void render() {
    long now = System.nanoTime();
    update();
    clearScreen();

    //		tiledMapHelper.getCamera().position.x = PIXELS_PER_METER * tokine.body.getPosition().x;
    camera.position.x = Constants.PIXELS_PER_METER * tokine.body.getPosition().x;

    handleScreenBoundaries();

    tiledMapHelper.getCamera().update();
    tiledMapHelper.render();

    batch.begin();
    tokine.render(batch, camera);
    batch.end();

    /** Draw this last, so we can see the collision boundaries on top of the sprites and map. */
    camera.update();
    debugRenderer.render(
        world,
        tiledMapHelper
            .getCamera()
            .combined
            .scale(
                Constants.PIXELS_PER_METER,
                Constants.PIXELS_PER_METER,
                Constants.PIXELS_PER_METER));

    if (now - lastRender < 30000000) { // 30 ms, ~33FPS
      try {
        Thread.sleep(30 - (now - lastRender) / 1000000);
      } catch (InterruptedException e) {
      }
    }
    lastRender = now;
  }
예제 #2
0
  @Override
  public void create() {
    super.create();

    /** If the viewport's size is not yet known, determine it here. */
    screenWidth = Gdx.graphics.getWidth();
    screenHeight = Gdx.graphics.getHeight();

    tiledMapHelper = new SimpleTiledMapHelper();
    tiledMapHelper.setResourceDirectory("data/tiledmap/cave");
    tiledMapHelper.loadMap("data/tiledmap/cave/cave.tmx");
    camera = (OrthographicCamera) tiledMapHelper.prepareCamera(screenWidth, screenHeight);

    tokine = new Tokine();
    tokine.initBody(world);

    tiledMapHelper.loadCollisions(
        "data/tiledmap/cave/CaveBaseForeground-collisions.txt", world, Constants.PIXELS_PER_METER);

    debugRenderer = new Box2DDebugRenderer(true, true, true, true, true);

    lastRender = System.nanoTime();
  }
예제 #3
0
 private void update() {
   tokine.update();
   world.step(Gdx.graphics.getDeltaTime(), 3, 3);
 }