@Override public Surface drawImage(Image image, float x, float y, float dw, float dh) { bindFramebuffer(); ((ImageGL) image) .draw(shader, topTransform(), x, y, dw, dh, 0, 0, image.width(), image.height(), tint); return this; }
@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; }
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()); } }); }
/** * Creates a new background using the given image. The image is assumed to be divided into a 3x1 * grid of 3 equal pieces. * * <p>NOTE: the image must be preloaded since we need to determine the stretching factor. If this * cannot be arranged using the application resource strategy, callers may consider setting the * background style from the images callback. */ public Scale3Background(Image image) { if (!image.isReady()) { // complain about this, we don't support asynch images PlayN.log().warn("Scale3 image not preloaded: " + image); } _image = image; _s3 = new Scale3(image.width(), image.height()); }
// used by GLContext.tex(Sub)Image2D impls protected static ByteBuffer getRgba(Image image) { int w = (int) image.width(), h = (int) image.height(), size = w * h; int[] rawPixels = new int[size]; ByteBuffer pixels = ByteBuffer.allocateDirect(size * 4); pixels.order(ByteOrder.nativeOrder()); IntBuffer rgba = pixels.asIntBuffer(); image.getRgb(0, 0, w, h, rawPixels, 0, w); for (int i = 0; i < size; i++) { int argb = rawPixels[i]; // Order is inverted because this is read as a byte array, and we store intel ints. rgba.put(i, ((argb >> 16) & 0x0ff) | (argb & 0x0ff00ff00) | ((argb & 0xff) << 16)); } return pixels; }
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); } }); }
@Override public Surface drawImageCentered(Image img, float x, float y) { return drawImage(img, x - img.width() / 2, y - img.height() / 2); }
@Override public Surface drawImage(Image image, float x, float y) { return drawImage(image, x, y, image.width(), image.height()); }
public int getHeight() { if (image != null) return image.height(); return 1; }
public int getWidth() { if (image != null) return image.width(); return 1; }
/** * Creates an instance with the supplied source image. The image is assumed to contain a complete * sheet of frames, each {@code width x height} in size. * * @param width the width of each frame. * @param height the width of each frame. */ public SimpleFrames(Image source, float width, float height) { this(source, width, height, (int) (source.height() / height) * (int) (source.width() / width)); }
/** * Creates an instance with the supplied source image. The frames are assumed to be all in a * single row, thus the height of the image defines the height of the frame. * * @param width the width of each frame. */ public SimpleFrames(Image source, float width) { this(source, width, source.height()); }