Esempio n. 1
0
  @Override
  public boolean loadAsset() {
    logger.info("Loading image " + descriptor.getUri());
    loaded = false;
    if (image == null) {
      try {
        String path = assetHandler.getAbsolutePath(descriptor.getUri().getPath());
        image = PlayN.assets().getImage(path);
        if (image != null) {
          logger.info(
              "Image loaded OK: {} from {} width {}",
              new Object[] {descriptor.getUri(), path, image.width()});
          return image.isReady();
        } else {
          logger.error("Image NOT loaded: {}", descriptor.getUri());
          return true;
        }
      } catch (Exception e) {
        logger.error("Error loading image: {}", descriptor.getUri(), e);
        return false;
      }
    }
    image.addCallback(
        new ResourceCallback<Image>() {

          @Override
          public void done(Image resource) {
            loaded = true;
          }

          @Override
          public void error(Throwable err) {}
        });
    return loaded;
  }
Esempio n. 2
0
  public TileImage(String imageName) {
    Image image = assetManager().getImage("images/" + imageName);
    imageLayer = graphics().createImageLayer(image);

    // TODO: remove these and replace with something useful
    final int width = 15;
    final int height = 15;

    image.addCallback(
        new ResourceCallback<Image>() {
          @Override
          public void done(Image image) {
            // since the image is loaded, we can use its width and height
            imageLayer.setWidth(image.width());
            imageLayer.setHeight(image.height());
            imageLayer.setOrigin(image.width() / 2f, image.height() / 2f);
            imageLayer.setScale(width / image.width(), height / image.height());

            // TODO: These values need to be set
            //        imageLayer.setTranslation(x, y);
            //        imageLayer.setRotation(angle);
          }

          @Override
          public void error(Throwable err) {
            PlayN.log().error("Error loading image: " + err.getMessage());
          }
        });
  }
Esempio n. 3
0
  public Hero(final GroupLayer heroLayer, final float x, final float y, float floorHeight) {
    Image image = assets().getImage(IMAGE);
    _heroLayer = graphics().createImageLayer(image);
    _floorHeight = floorHeight;

    // Add a callback for when the image loads.
    // This is necessary because we can't use the width/height (to center the
    // image) until after the image has been loaded
    image.addCallback(
        new ResourceCallback<Image>() {
          @Override
          public void done(Image image) {

            _heroHeight = graphics().height() / _size;
            _heroWidth = (image.width() * _heroHeight) / image.height();

            _heroLayer.setHeight(_heroHeight);
            _heroLayer.setWidth(_heroWidth);

            _heroLayer.setOrigin(_heroWidth / 2f, _heroHeight / 2f);
            _heroLayer.setTranslation(x, y);

            // _heroLayer.setScale(0.2f);
            heroLayer.add(_heroLayer);

            _x = x;
            _y = y;

            // the center of the image is its height/2 and afterwards we scale it per 0.2 (1/5)
            // _heroHeight = image.height() / 10f;
          }

          @Override
          public void error(Throwable err) {
            log().error("Error loading image!", err);
          }
        });
  }