コード例 #1
0
  @Override
  protected void onManagedUpdate(float pSecondsElapsed) {
    int sectorX =
        (int) Math.floor(this.getSectorX(this.camera.getXMin() + this.camera.getWidth() / 2));
    int sectorY =
        (int) Math.floor(this.getSectorY(this.camera.getYMin() + this.camera.getHeight() / 2));

    if (sectorX != this.lastChangedSectorX || sectorY != this.lastChangedSectorY)
      for (int i = -1; i < 2; i++) {
        for (int j = -1; j < 2; j++) {
          StarsSector tmp = this.getSector(sectorX + i, sectorY + j);
          if (tmp == null) {
            StarsSector tmp2 = this.getOutsideSector(sectorX, sectorY);
            if (tmp2 != null) {
              tmp2.setPosX(sectorX + i);
              tmp2.setPosY(sectorY + j);
            }
          }
        }
      }
    this.lastChangedSectorX = sectorX;
    this.lastChangedSectorY = sectorY;

    for (StarsSector sector : this.starSectors) {
      sector.getEntity().setX(sector.getPos().x * sectorW + this.camera.getXMin() * scrollFactor);
      sector.getEntity().setY(sector.getPos().y * sectorH + this.camera.getYMin() * scrollFactor);
    }

    this.camera.onUpdate(pSecondsElapsed);
  }