本文整理汇总了Java中org.newdawn.slick.util.ResourceLoader类的典型用法代码示例。如果您正苦于以下问题:Java ResourceLoader类的具体用法?Java ResourceLoader怎么用?Java ResourceLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceLoader类属于org.newdawn.slick.util包,在下文中一共展示了ResourceLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: XMLPackedSheet
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Create a new XML packed sheet from the XML output by the slick tool
*
* @param imageRef The reference to the image
* @param xmlRef The reference to the XML
* @throws SlickException Indicates a failure to parse the XML or read the image
*/
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
image = new Image(imageRef, false, Image.FILTER_NEAREST);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));
NodeList list = doc.getElementsByTagName("sprite");
for (int i=0;i<list.getLength();i++) {
Element element = (Element) list.item(i);
String name = element.getAttribute("name");
int x = Integer.parseInt(element.getAttribute("x"));
int y = Integer.parseInt(element.getAttribute("y"));
int width = Integer.parseInt(element.getAttribute("width"));
int height = Integer.parseInt(element.getAttribute("height"));
sprites.put(name, image.getSubImage(x,y,width,height));
}
} catch (Exception e) {
throw new SlickException("Failed to parse sprite sheet XML", e);
}
}
示例2: loadDefinition
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Load the definition file and parse each of the sections
*
* @param def The location of the definitions file
* @param trans The color to be treated as transparent
* @throws SlickException Indicates a failure to read or parse the definitions file
* or referenced image.
*/
private void loadDefinition(String def, Color trans) throws SlickException {
BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));
try {
image = new Image(basePath+reader.readLine(), false, filter, trans);
while (reader.ready()) {
if (reader.readLine() == null) {
break;
}
Section sect = new Section(reader);
sections.put(sect.name, sect);
if (reader.readLine() == null) {
break;
}
}
} catch (Exception e) {
Log.error(e);
throw new SlickException("Failed to process definitions file - invalid format?", e);
}
}
示例3: init
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
*/
public void init(GameContainer container) throws SlickException {
SoundStore.get().setMaxSources(32);
myContainer = container;
sound = new Sound("testdata/restart.ogg");
charlie = new Sound("testdata/cbrown01.wav");
try {
engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
} catch (IOException e) {
throw new SlickException("Failed to load engine", e);
}
music = musica = new Music("testdata/SMB-X.XM");
//music = musica = new Music("testdata/theme.ogg", true);
musicb = new Music("testdata/kirby.ogg", true);
burp = new Sound("testdata/burp.aif");
music.play();
}
示例4: getBuildDate
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Returns the build date, or the current date if not available.
*/
public int getBuildDate() {
if (buildDate == -1) {
Date date = null;
try {
Properties props = new Properties();
props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
String build = props.getProperty("build.date");
if (build == null || build.equals("${timestamp}") || build.equals("${maven.build.timestamp}"))
date = new Date();
else {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH);
date = format.parse(build);
}
} catch (Exception e) {
date = new Date();
} finally {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
buildDate = Integer.parseInt(dateFormat.format(date));
}
}
return buildDate;
}
示例5: init
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Initializes all fonts.
* @throws SlickException if ASCII glyphs could not be loaded
* @throws FontFormatException if any font stream data does not contain the required font tables
* @throws IOException if a font stream cannot be completely read
*/
public static void init() throws SlickException, FontFormatException, IOException {
float fontBase = 12f * GameImage.getUIscale();
Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME));
Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
DEFAULT = new UnicodeFont(font);
BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2));
SMALL = new UnicodeFont(font.deriveFont(fontBase));
SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase));
ColorEffect colorEffect = new ColorEffect();
loadFont(DEFAULT, colorEffect);
loadFont(BOLD, colorEffect);
loadFont(XLARGE, colorEffect);
loadFont(LARGE, colorEffect);
loadFont(MEDIUM, colorEffect);
loadFont(MEDIUMBOLD, colorEffect);
loadFont(SMALL, colorEffect);
loadFont(SMALLBOLD, colorEffect);
}
示例6: loadClip
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Loads and returns a Clip from a resource.
* @param ref the resource name
* @param isMP3 true if MP3, false if WAV
* @return the loaded and opened clip
*/
private static MultiClip loadClip(String ref, boolean isMP3) {
try {
URL url = ResourceLoader.getResource(ref);
// check for 0 length files
InputStream in = url.openStream();
if (in.available() == 0) {
in.close();
return new MultiClip(ref, null);
}
in.close();
AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
return loadClip(ref, audioIn, isMP3);
} catch (Exception e) {
explode(String.format("Failed to load file '%s'.", ref), e, DEFAULT_OPTIONS);
return null;
}
}
示例7: getSoundFileName
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Returns the sound file name, with extension, by first looking through
* the skins directory and then the default resource locations.
* @param filename the base file name
* @return the full file name, or null if no file found
*/
private static String getSoundFileName(String filename) {
String wav = String.format("%s.wav", filename), mp3 = String.format("%s.mp3", filename);
File skinDir = SkinService.skin.getDirectory();
if (skinDir != null) {
File skinWAV = new File(skinDir, wav), skinMP3 = new File(skinDir, mp3);
if (skinWAV.isFile())
return skinWAV.getAbsolutePath();
if (skinMP3.isFile())
return skinMP3.getAbsolutePath();
}
if (ResourceLoader.resourceExists(wav))
return wav;
if (ResourceLoader.resourceExists(mp3))
return mp3;
return null;
}
示例8: loadResources
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Load resources.
*/
public static void loadResources() {
try {
//Load bitmap fonts
loadBitmapFonts();
// Textures
textures.put("whoops", new AnimationData("res/whoops.png"));
loadTextures();
//load audio
audio.put("miss", AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));
} catch (IOException e) {
int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
System.out.println(max);
e.printStackTrace();
}
System.gc();
}
示例9: getTextureData
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Gets the texture data.
*
* @param string the string
* @return the texture data
*/
public static AnimationData getTextureData(String string) {
AnimationData t = textures.get(string);
if(t != null) {
return t;
} else {
//try to get it, in case we forgot
System.err.println("Warn: " + string + " not explicitly defined");
for(String loc: searchFolders){
if(ResourceLoader.resourceExists("res/" + loc + "/" + string + ".png")){
AnimationData txt = new AnimationData("res/" + loc + "/" + string + ".png");
textures.put(string, txt);
return txt;
}
}
return textures.get("whoops");
}
}
示例10: getAudio
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Gets the audio.
*
* @param name the name
* @return the audio
*/
public static Audio getAudio(String name) {
Audio a = audio.get(name);
if(a == null) {
// System.err.println("Warn: " + name + " not explicitly defined");
try{
Audio b = AudioLoader.getAudio("WAV",
ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
audio.put(name, b);
return b;
} catch (Exception e){
return null;
}
} else {
return a;
}
}
示例11: loadMap
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
public void loadMap(String name) {
try {
ObjectInputStream oos = new ObjectInputStream(ResourceLoader
.getResourceAsStream(GamePanel.resfolder + "stages" + File.separator + name + ".map"));
TileMapData data = (TileMapData) oos.readObject();
this.tiles = data.tiles;
width = data.width;
height = data.height;
oos.close();
return;
} catch (Exception e) {
System.err.println("Map: '" + name + "' is corrupt");
e.printStackTrace();
}
}
示例12: loadSound
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
public void loadSound(String fileName, String exe) {
try {
String withoutDot = exe.replace(".", "");
if (exe == ".ogg") {
audio = AudioLoader.getAudio(withoutDot.toUpperCase(),
ResourceLoader.getResourceAsStream("sound/" + fileName + exe));
} else if (exe == ".xm") {
audio = AudioLoader.getStreamingAudio("MOD",
ResourceLoader.getResource("sound/" + fileName + exe.toUpperCase()));
} else if (exe == ".aif") {
audio = AudioLoader.getAudio(withoutDot.toUpperCase(),
ResourceLoader.getResourceAsStream("sound/" + fileName + exe));
} else if (exe == ".wav") {
audio = AudioLoader.getAudio(withoutDot.toUpperCase(),
ResourceLoader.getResourceAsStream("sound/" + fileName + exe));
} else {
System.out.println("Only Support OGG MOD AIF or WAV");
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: Score
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Initialise resources
*/
public Score() {
readHighScore();
//load a default java font
Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
font = new TrueTypeFont(awtFont, antiAlias);
// load font from file
try {
InputStream inputStream = ResourceLoader.getResourceAsStream("res/fonts/brick.ttf");
Font awtFont2 = Font.createFont(Font.TRUETYPE_FONT, inputStream);
awtFont2 = awtFont2.deriveFont(50f); // set font size
font2 = new TrueTypeFont(awtFont2, antiAlias);
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: Sounds
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
public void Sounds(){
try {
// oggEffect = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("testdata/restart.ogg"));
// oggStream = AudioLoader.getStreamingAudio("OGG", ResourceLoader.getResource("testdata/bongos.ogg"));
// 102.modStream = AudioLoader.getStreamingAudio("MOD", ResourceLoader.getResource("testdata/SMB-X.XM"));
//modStream.playAsMusic(1.0f, 1.0f, true);
// aifEffect = AudioLoader.getAudio("AIF", ResourceLoader.getResourceAsStream("testdata/burp.aif"));
// wavEffect = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/cbrown01.wav"));
wavHitTree = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("/res/sounds/hittree.wav"));
oggHitTree = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("res/sounds/hittree.ogg"));
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: getBuildDate
import org.newdawn.slick.util.ResourceLoader; //导入依赖的package包/类
/**
* Returns the build date, or the current date if not available.
*/
public int getBuildDate() {
if (buildDate == -1) {
Date date = null;
try {
Properties props = new Properties();
props.load(ResourceLoader.getResourceAsStream(Options.VERSION_FILE));
String build = props.getProperty("build.date");
if (build == null || build.equals("${timestamp}") || build.equals("${maven.build.timestamp}"))
date = new Date();
else {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH);
date = format.parse(build);
}
} catch (Exception e) {
date = new Date();
} finally {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
buildDate = Integer.parseInt(dateFormat.format(date));
}
}
return buildDate;
}