/** * Registers a font with the graphics system. * * @param name the name under which to register the font. * @param path the path to the font resource (relative to the asset manager's path prefix). * Currently only TrueType ({@code .ttf}) fonts are supported. */ public void registerFont(String name, String path) { try { _fonts.put(name, ((JavaAssets) assets()).requireResource(path).createFont()); } catch (Exception e) { platform.reportError("Failed to load font [name=" + name + ", path=" + path + "]", e); } }
public ByteBuffer readBytes() throws IOException { return ByteBuffer.wrap(toByteArray(openStream())); } public String readString() throws Exception {
public String readString() throws Exception { return new String(readBytes(), "UTF-8"); } }
for (Scale.ScaledResource rsrc : assetScale().getScaledResources(fullPath)) { try { BufferedImage image = requireResource(rsrc.path).readImage();
public void run () { try { AudioInputStream ais = rsrc.openAudioStream(); AudioFormat format = ais.getFormat(); Clip clip;
public void run () { try { AudioInputStream ais = rsrc.openAudioStream(); AudioFormat format = ais.getFormat(); Clip clip;
for (Scale.ScaledResource rsrc : assetScale().getScaledResources(fullPath)) { try { BufferedImage image = requireResource(rsrc.path).readImage();
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { BufferedImage image = requireResource(rsrc.path).readImage(); // if image is at a higher scale factor than the view, scale to the view display factor Scale viewScale = plat.graphics().scale(), imageScale = rsrc.scale; float viewImageRatio = viewScale.factor / imageScale.factor; if (viewImageRatio < 1) { image = scaleImage(image, viewImageRatio); imageScale = viewScale; } if (plat.config.convertImagesOnLoad) { BufferedImage convertedImage = JavaGraphics.convertImage(image); if (convertedImage != image) { plat.log().debug("Converted image: " + path + " [type=" + image.getType() + "]"); image = convertedImage; } } return new ImageImpl.Data(imageScale, image, image.getWidth(), image.getHeight()); } catch (FileNotFoundException fnfe) { error = fnfe; // keep going, checking for lower resolution images } } plat.log().warn("Could not load image: " + path + " [error=" + error + "]"); throw error != null ? error : new FileNotFoundException(path); }
public void run () { try { AudioInputStream ais = rsrc.openAudioStream(); Clip clip = AudioSystem.getClip(); if (music) { clip = new BigClip(clip); } AudioFormat baseFormat = ais.getFormat(); if (baseFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { AudioFormat decodedFormat = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, // we have to force sample size to 16 baseFormat.getChannels(), baseFormat.getChannels()*2, baseFormat.getSampleRate(), false // big endian ); ais = AudioSystem.getAudioInputStream(decodedFormat, ais); } clip.open(ais); dispatchLoaded(sound, clip); } catch (Exception e) { dispatchLoadError(sound, e); } } });
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { BufferedImage image = requireResource(rsrc.path).readImage(); // if image is at a higher scale factor than the view, scale to the view display factor Scale viewScale = plat.graphics().scale(), imageScale = rsrc.scale; float viewImageRatio = viewScale.factor / imageScale.factor; if (viewImageRatio < 1) { image = scaleImage(image, viewImageRatio); imageScale = viewScale; } if (plat.config.convertImagesOnLoad) { BufferedImage convertedImage = JavaGraphics.convertImage(image); if (convertedImage != image) { plat.log().debug("Converted image: " + path + " [type=" + image.getType() + "]"); image = convertedImage; } } return new ImageImpl.Data(imageScale, image, image.getWidth(), image.getHeight()); } catch (FileNotFoundException fnfe) { error = fnfe; // keep going, checking for lower resolution images } } plat.log().warn("Could not load image: " + path + " [error=" + error + "]"); throw error != null ? error : new FileNotFoundException(path); }
public void run () { try { AudioInputStream ais = rsrc.openAudioStream(); Clip clip = AudioSystem.getClip(); if (music) { clip = new BigClip(clip); } AudioFormat baseFormat = ais.getFormat(); if (baseFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { AudioFormat decodedFormat = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, // we have to force sample size to 16 baseFormat.getChannels(), baseFormat.getChannels()*2, baseFormat.getSampleRate(), false // big endian ); ais = AudioSystem.getAudioInputStream(decodedFormat, ais); } clip.open(ais); dispatchLoaded(sound, clip); } catch (Exception e) { dispatchLoadError(sound, e); } } });
@Override public String getTextSync(String path) throws Exception { return requireResource(path).readString(); }
public AudioInputStream openAudioStream() throws Exception { return AudioSystem.getAudioInputStream(openStream()); } public Font createFont() throws Exception {
@Override public byte[] getBytesSync(String path) throws Exception { return requireResource(path).readBytes(); }
public String readString() throws Exception { return new String(toByteArray(openStream()), "UTF-8"); } }
@Override public String getTextSync(String path) throws Exception { return requireResource(path).readString(); }
/** * Registers a font with the graphics system. * * @param name the name under which to register the font. * @param path the path to the font resource (relative to the asset manager's path prefix). * Currently only TrueType ({@code .ttf}) fonts are supported. */ public void registerFont(String name, String path) { try { _fonts.put(name, ((JavaAssets) assets()).requireResource(path).createFont()); } catch (Exception e) { platform.reportError("Failed to load font [name=" + name + ", path=" + path + "]", e); } }
public Font createFont() throws Exception { return Font.createFont(Font.TRUETYPE_FONT, openStream()); } public ByteBuffer readBytes() throws IOException {
public byte[] readBytes() throws IOException { return toByteArray(openStream()); } public String readString() throws Exception {
public Font createFont() throws Exception { return Font.createFont(Font.TRUETYPE_FONT, openStream()); } public byte[] readBytes() throws IOException {