/** * Asynchronously loads and returns the image at the specified URL. The width and height of the * image will be unset (0) until the image is loaded. <em>Note:</em> on non-HTML platforms, this * spawns a new thread for each loaded image. Thus, attempts to load large numbers of remote * images simultaneously may result in poor performance. */ public Image getRemoteImage (String url) { return getRemoteImage(url, 0, 0); }
/** * Asynchronously loads and returns the image at the specified URL. The width and height of the * image will be unset (0) until the image is loaded. <em>Note:</em> on non-HTML platforms, this * spawns a new thread for each loaded image. Thus, attempts to load large numbers of remote * images simultaneously may result in poor performance. */ public Image getRemoteImage (String url) { return getRemoteImage(url, 0, 0); }
@Override public Image getRemoteImage(String url) { Object object = null; if ((object = cache.get(url)) == null) { object = delegate.getRemoteImage(url); cache.put(url, object); } return (Image) object; }
@Override public Image getRemoteImage(String url, float width, float height) { Object object = null; if ((object = cache.get(url)) == null) { object = delegate.getRemoteImage(url, width, height); cache.put(url, object); } return (Image) object; }
@Override public final Image getRemoteImage(String url) { incrementRequestCount(); Image image = delegate.getRemoteImage(url); image.addCallback(callback); return image; }
@Override public final Image getRemoteImage(String url, float width, float height) { incrementRequestCount(); Image image = delegate.getRemoteImage(url, width, height); image.addCallback(callback); return image; }
@Override public void init() { Image orange = game.assets.getImage("images/orange.png"); ImageLayer l1 = new ImageLayer(orange); game.rootLayer.addAt(l1.setScale(2).setRotation(FloatMath.PI/8), 50, 50); l1.events().connect(new Mover(l1).listener(game.input)); ImageLayer l2 = new ImageLayer(orange); game.rootLayer.addAt(l2.setScale(1.5f).setRotation(FloatMath.PI/4), 150, 50); l2.events().connect(new Mover(l2).listener(game.input)); Image mdb = game.assets.getRemoteImage("https://www.samskivert.com/images/headshot.jpg"); ImageLayer l3 = new ImageLayer(mdb); game.rootLayer.addAt(l3.setRotation(-FloatMath.PI/4), 50, 150); l3.events().connect(new Mover(l3).listener(game.input)); String l4url = "https://www.samskivert.com/images/2012/12/spellwood-app-icon.png"; game.net.req(l4url).execute().onSuccess(rsp -> { try { Image icon = rsp.payloadImage(new Scale(2)); ImageLayer l4 = new ImageLayer(icon); game.rootLayer.addAt(l4.setRotation(FloatMath.PI/4), 150, 150); l4.events().connect(new Mover(l4).listener(game.input)); } catch (Exception e) { game.log.warn("Failed to decode image: " + e); } }).onFailure(t -> game.log.warn("Failed to load image: " + l4url, t)); }
@Override public void init() { Image orange = assets().getImage("images/orange.png"); Image mdb = assets().getRemoteImage("https://graph.facebook.com/samskivert/picture");