當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceLoader.getResourceAsStream方法代碼示例

本文整理匯總了Java中org.newdawn.slick.util.ResourceLoader.getResourceAsStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourceLoader.getResourceAsStream方法的具體用法?Java ResourceLoader.getResourceAsStream怎麽用?Java ResourceLoader.getResourceAsStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.newdawn.slick.util.ResourceLoader的用法示例。


在下文中一共展示了ResourceLoader.getResourceAsStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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);
	}
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:31,代碼來源:PackedSpriteSheet.java

示例2: 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();
	}
}
 
開發者ID:Timbals,項目名稱:YellowSquare,代碼行數:17,代碼來源:TileMap.java

示例3: 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();
    }
}
 
開發者ID:harryi3t,項目名稱:Save-The-Ball,代碼行數:22,代碼來源:Score.java

示例4: 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, @Nullable Color trans) throws SlickException {
    try (
            final InputStream resourceAsStream = ResourceLoader.getResourceAsStream(def);
            final Reader inputStreamReader = new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8);
            final BufferedReader reader = new BufferedReader(inputStreamReader)) {
        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);
    }
}
 
開發者ID:FOShameDotOrg,項目名稱:fuzzy-octo-shame,代碼行數:32,代碼來源:PackedSpriteSheet.java

示例5: loadTextureLinear

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
public static int loadTextureLinear(String filename){
    int texture = glGenTextures();
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
    InputStream in;
    try {
        in = ResourceLoader.getResourceAsStream("res/textures/"+filename);
        PNGDecoder decoder = new PNGDecoder(in);
        ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
        buffer.flip();
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    } catch (IOException e) {
        e.printStackTrace();
    }
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

    return texture;
}
 
開發者ID:Piratkopia13,項目名稱:Pixel-Planet,代碼行數:21,代碼來源:GameResourceLoader.java

示例6: loadShader

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
public static String loadShader(String filename){
    StringBuilder shaderSource = new StringBuilder();
    BufferedReader shaderReader = null;

    try {
        shaderReader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream("res/shaders/" + filename)));
        String line;
        while ((line = shaderReader.readLine()) != null){
            shaderSource.append(line).append("\n");
        }

        shaderReader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return shaderSource.toString();
}
 
開發者ID:Piratkopia13,項目名稱:Pixel-Planet,代碼行數:19,代碼來源:GameResourceLoader.java

示例7: getProgramCode

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
/**
 * Gets the program code from the file <tt>filename</tt> and puts it into a
 * <tt>ByteBuffer</tt>.
 *
 * @param filename
 *            the full name of the file.
 * @return a ByteBuffer containing the program code.
 * @throws SlickException
 */
private ByteBuffer getProgramCode(String filename) throws SlickException {
    InputStream fileInputStream;
    byte[] shaderCode;

    fileInputStream = ResourceLoader.getResourceAsStream(filename);
    DataInputStream dataStream = new DataInputStream(fileInputStream);
    try {
        dataStream.readFully(shaderCode = new byte[fileInputStream.available()]);
        fileInputStream.close();
        dataStream.close();
    } catch (IOException e) {
        throw new SlickException(e.getMessage());
    }

    ByteBuffer shaderPro = BufferUtils.createByteBuffer(shaderCode.length);

    shaderPro.put(shaderCode);
    shaderPro.flip();

    return shaderPro;
}
 
開發者ID:Pheelbert,項目名稱:cretion,代碼行數:31,代碼來源:ShaderManagerImpl.java

示例8: loadBitmapFonts

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
/**
 * Load bitmap fonts.
 */
public static void loadBitmapFonts() {
	Scanner in = new Scanner(ResourceLoader.getResourceAsStream("res/fonts/fonts.txt"));
	while(in.hasNextLine()) {
		String line = in.nextLine();
		if(line.startsWith("#"))
			continue;
		if(line.startsWith("define")) {
			String name = line.split(":")[1];
			String texName = in.nextLine();
			char[] chars = in.nextLine().toCharArray();
			int height = Integer.parseInt(in.nextLine());
			int spacing = Integer.parseInt(in.nextLine());
			char[] widths = in.nextLine().toCharArray();
			
			BitmapFont font = new BitmapFont(texName);
			font.setHeight(height);
			font.setSpacing(spacing);
			int pos = 0;
			for(int i=0; i<chars.length; i++) {
				int width = Integer.parseInt(widths[i]+"");
				font.put(chars[i], pos, width);
				pos += width;
			}
			bitmapFonts.put(name, font);
			System.out.println(name+"(bitmap font) loaded");
		}
	}
	in.close();
}
 
開發者ID:eliatlarge,項目名稱:FEMultiPlayer-V2,代碼行數:33,代碼來源:FEResources.java

示例9: load

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
/**
 * Carrega os dados do arquivo.
 */
private void load() throws SlickException {
	InputStream is = ResourceLoader.getResourceAsStream(this.path);
	BufferedReader input = new BufferedReader(new InputStreamReader(is));
	
	String line = null;	
	int i = 0;
	try {
		while ((line = input.readLine()) != null){
			if (line.trim().equals("tiles [")) { 					
				currentArea = 0;
				continue;
			} else if (line.trim().equals("]")) {
				continue;
			}
			
			switch (currentArea) {
				case 0: //tiles
					this.parseTileData(line, i++);
					break;
			}
		}
		
		input.close();
	} catch (IOException e) { 
		e.printStackTrace();
	}
}
 
開發者ID:intentor,項目名稱:telyn,代碼行數:31,代碼來源:LayerConfiguration.java

示例10: loadDefinition

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
/**
 * Carrega o arquivo de defini��o e cria as se��es.
 * @param def 	Caminho do arquivo de defini��o.
 * @param trans Cor a ser tratada como transpar�ncia.
 */
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;
			this.sections.add(new PackedSpriteSection(reader, this.image));				
			if (reader.readLine() == null) break;
		}
	} catch (Exception e) {
		throw new SlickException("Falha no processamento do arquivo de defini��o. Talvez o formato seja inv�lido?", e);
	}
}
 
開發者ID:intentor,項目名稱:telyn,代碼行數:20,代碼來源:PackedSpriteSheet.java

示例11: LoadTexture

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
public static Texture LoadTexture(String path, String fileType) {
	Texture tex = null;
	InputStream in = ResourceLoader.getResourceAsStream(path);
	try {
		tex = TextureLoader.getTexture(fileType, in);
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	return tex;
}
 
開發者ID:massm039,項目名稱:SRPG,代碼行數:12,代碼來源:Artist.java

示例12: LoadPNG

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
public static Texture LoadPNG(String fileName) {
	Texture tex = null;
	InputStream in = ResourceLoader.getResourceAsStream("res/" + fileName + ".png");
	try {
		tex = TextureLoader.getTexture("PNG", in);
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	return tex;
}
 
開發者ID:massm039,項目名稱:SRPG,代碼行數:12,代碼來源:Artist.java

示例13: TextBox

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
public TextBox(String font) {
	try {
		InputStream inputStream = ResourceLoader.getResourceAsStream(font);
		Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
		awtFont = awtFont.deriveFont(32f); //font size
		this.font = new TrueTypeFont(awtFont, false);
	}
	catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:massm039,項目名稱:SRPG,代碼行數:12,代碼來源:TextBox.java

示例14: changeFont

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
public void changeFont(String font) {
	try {
		InputStream inputStream = ResourceLoader.getResourceAsStream(font);
		Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
		awtFont = awtFont.deriveFont(32f); //font size
		this.font = new TrueTypeFont(awtFont, false);
	}
	catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:massm039,項目名稱:SRPG,代碼行數:12,代碼來源:TextBox.java

示例15: LoadTexture

import org.newdawn.slick.util.ResourceLoader; //導入方法依賴的package包/類
/**
 * Método para crear una texura
 * 
 * @param path Path de la textura
 * @param fileType Tipo de la textura
 * @return Textura
 * 
 * @author Alba Ríos
 */
public static Texture LoadTexture(String path, String fileType){
    System.out.println( System.getProperty("user.dir"));
    Texture tex = null;
    InputStream in = ResourceLoader.getResourceAsStream(path);
    try {
        tex = TextureLoader.getTexture(fileType, in);
    } catch (IOException ex) {
        Logger.getLogger(Artist.class.getName()).log(Level.SEVERE, null, ex);
    }
    return tex;
}
 
開發者ID:Trifido,項目名稱:star-droids,代碼行數:21,代碼來源:Artist.java


注:本文中的org.newdawn.slick.util.ResourceLoader.getResourceAsStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。