@Override public Image getImage(String path) { Object object = null; if ((object = cache.get(path)) == null) { object = delegate.getImage(path); cache.put(path, object); } return (Image) object; }
/** * Asynchronously loads and returns a music resource. On some platforms, the backend will use a * different implementation from {@link #getSound} which is better suited to the much larger size * of music audio data. * * <p> Note: if a request to play the sound is made before the sound is loaded, it will be noted * and the sound will be played when loading has completed. * * @param path the path to the sound resource. NOTE: this should not include a file extension, * PlayN will automatically add {@code .mp3}, (or {@code .caf} on iOS). */ public Sound getMusic (String path) { return getSound(path); }
/** * 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); }
public class FishyDash extends Game { Assets assets; public void create(){ assets = new Assets(); assets.load(); //.... } } public class MainMenuScreen implements Screen{ //... public void show() { System.out.println("second"); jumpSound = game.assets.manager.get(Assets.jumpSound, Sound.class); //... } //... }
/** * Synchronously loads and returns an image. The calling thread will block while the image is * loaded from disk and decoded. When this call returns, the image's width and height will be * valid, and the image can be immediately converted to a texture and drawn into a canvas. * * @param path the path to the image asset. * @throws UnsupportedOperationException on platforms that cannot support synchronous asset * loading (HTML). */ public Image getImageSync (String path) { ImageImpl image = createImage(false, 0, 0, path); try { image.succeed(load(path)); } catch (Throwable t) { image.fail(t); } 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)); }
Image sheet = assets().getImage("images/spritesheet.png"); SimpleFrames frames = new SimpleFrames(sheet, 60, 60, 60); iface.anim.repeat(box).flipbook(box, new Flipbook(frames, 66)); final Image packed = assets().getImage("images/orb_burst.png"); assets().getText("images/orb_burst.json").onSuccess(new Slot<String>() { public void onEmit (String json) { GroupLayer box = new GroupLayer();
@Override public String getTextSync(String path) throws Exception { // no tracking for text loading return delegate.getTextSync(path); }
@Override public byte[] getBytesSync(String path) throws Exception { // no caching for arbitrary binary loading return delegate.getBytesSync(path); }
@Override public Sound getMusic(String path) { Object object = null; if ((object = cache.get(path)) == null) { object = delegate.getMusic(path); cache.put(path, object); } return (Sound) object; }
@Override public void getText(String path, Callback<String> callback) { // no tracking for text loading delegate.getText(path, callback); }
@Override public Image getImageSync(String path) { Object object = null; if ((object = cache.get(path)) == null) { object = delegate.getImageSync(path); cache.put(path, object); } return (Image) object; }
@Override public void getBytes(String path, Callback<byte[]> callback) { // no caching for arbitrary binary loading delegate.getBytes(path, callback); } }
private Assets assets; @Override public void create () { assets.load(); //or call the assets.finishLoading(); while(!assets.manager.update()) { System.out.println(assets.manager.getProgress()*100+"%"); } setScreen(new GameScreen(assets)); //pass it to the gamescreen ctro! }
@Override public void init() { Image orange = assets().getImage("images/orange.png"); Image mdb = assets().getRemoteImage("https://graph.facebook.com/samskivert/picture");
@Override public String getTextSync(String path) throws Exception { // no caching for text loading return delegate.getTextSync(path); }
@Override public byte[] getBytesSync(String path) throws Exception { // no tracking for arbitrary binary loading return delegate.getBytesSync(path); }
@Override protected Sound loadSound (String path) { return plat.assets().getMusic(path); } }
@Override public void getText(String path, Callback<String> callback) { // no caching for text loading delegate.getText(path, callback); }
/** * Synchronously loads and returns an image. The calling thread will block while the image is * loaded from disk and decoded. When this call returns, the image's width and height will be * valid, and the image can be immediately converted to a texture and drawn into a canvas. * * @param path the path to the image asset. * @throws UnsupportedOperationException on platforms that cannot support synchronous asset * loading (HTML). */ public Image getImageSync (String path) { ImageImpl image = createImage(false, 0, 0, path); try { image.succeed(load(path)); } catch (Throwable t) { image.fail(t); } return image; }