Azzet是一个简单的Java类库,用于从不同的源中加载资源。
示例代码:
BufferedImage img = Assets.load("https://www.google.com/logos/classicplus.png"); // loaded from websiteFont fnt = Assets.load("myfont.ttf", new FontInfo(32.0f)); // loaded from classpathClip snd = Assets.load("C:\UserData\MyMusic.wav"); // loaded from file-systemBufferedImage gif = Assets.loadFrom("mygif.gif", BufferedImage.class); // you can request the return typeBufferedImage[] animatedGif = Assets.loadFrom("mygif.gif", "db"); // loads from DatabaseSource saved as "db"Properties props = Assets.loadFrom("app.properties", "tcp"); // loads from TcpSource saved as "tcp"支持的格式包括:
JSON(org.magnos.asset.json.JsonValue)
XML(org.w3c.dom.Document)
PROPERTIES/XML/CONFIG(java.util.Properties,org.magnos.asset.props.Config)
GIF(java.awt.image.BufferedImage[])
PNG/BMP/WBMP/JPEG/JPG(java.awt.image.BufferedImage)
MID/MIDI(javax.sound.midi.Sequence)
WAV/AU/AIFF/SND(javax.sound.sampled.Clip)
TTF(java.awt.Font)
CSV(org.magnos.asset.csv.Table)
CLASS/CLAZZ(java.lang.Class)
JAR(org.magnos.asset.java.Jar)
ZIP(org.magnos.asset.zip.Zip)
GZ(org.magnos.asset.AssetInfo)
DAT(byte[],java.io.InputStream,java.nio.ByteBuffer,java.io.ByteArrayOutputStream)
TXT(java.lang.String,char[],java.nio.CharBuffer,java.lang.StringBuffer,java.lang.StringBuilder)
支持的数据源:
Classpath
File-System
Database
JAR
FTP
HTTP/HTTPS
UDP
TCP
SSL
UDPMulticast
示例代码:
FutureAssetBundle bundle = new FutureAssetBundle();bundle.add( Assets.loadFuture("image.gif", BufferedImage.class) );bundle.add( Assets.loadFuture("sound.wav", Clip.class) );BufferedImage image = null;Clip sound = null;// game loopwhile (running) { // do stuff // this occurs during the loading screen.... if (bundle.isComplete()) { bundle.loaded(); // notify all FutureAsset implementations the asset has been accepted. image = bundle.getAsset("image.gif"); sound = bundle.getAsset("sound.wav"); // move from loading to play screen } else { display bundle.percentComplete(); } // do other stuff}
评论