Refine search
@Override public void create () { font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); }
@Override protected Shader createShader (Renderable renderable) { if (config.vertexShader != null && config.fragmentShader != null && tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) { String prefix = DefaultShader.createPrefix(renderable, config); Gdx.files.absolute(tempFolder).child(name + ".vertex.glsl").writeString(prefix + config.vertexShader, false); Gdx.files.absolute(tempFolder).child(name + ".fragment.glsl").writeString(prefix + config.fragmentShader, false); } BaseShader result = new MultiPassShader(renderable, config); if (tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) Gdx.files.absolute(tempFolder).child(name + ".log.txt").writeString(result.program.getLog(), false); return result; } }
public FileHandle sibling (String name) { name = name.replace('\\', '/'); if (file.getPath().length() == 0) throw new GdxRuntimeException("Cannot get the sibling of the root."); return Gdx.files.getFileHandle(new File(file.getParent(), name).getPath(), type); //this way we can find the sibling even if it's inside the obb }
@Override public void create () { // copy an internal mp3 to the external storage FileHandle src = Gdx.files.internal("data/8.12.mp3"); FileHandle dst = Gdx.files.external("8.12.mp3"); src.copyTo(dst); // create a music instance and start playback Music music = Gdx.audio.newMusic(dst); music.play(); }
private void testAbsolute () throws IOException { String path = new File(Gdx.files.getExternalStoragePath(), "meow").getAbsolutePath(); FileHandle handle = Gdx.files.absolute(path); handle.delete(); if (handle.exists()) fail(); if (handle.isDirectory()) fail(); if (handle.delete()) fail(); if (handle.list().length != 0) fail(); if (!handle.exists()) fail(); if (handle.length() != 3) fail(); FileHandle copy = Gdx.files.absolute(path + "-copy"); copy.delete(); if (copy.exists()) fail(); if (!copy.exists()) fail(); if (copy.length() != 3) fail(); FileHandle move = Gdx.files.absolute(path + "-move"); move.delete(); if (move.exists()) fail();
private void testInternal () throws IOException { FileHandle handle = Gdx.files.internal("data/badlogic.jpg"); if (!handle.exists()) fail("Couldn't find internal file"); if (handle.isDirectory()) fail("Internal file shouldn't be a directory"); try { handle.delete(); fail("Shouldn't be able to delete internal file"); } catch (Exception expected) { } catch (Exception ignored) { FileHandle dir = Gdx.files.internal("data"); if (Gdx.app.getType() != ApplicationType.Android) { if (!dir.exists()) fail(); if (!child.parent().exists()) fail(); FileHandle copy = Gdx.files.external("badlogic.jpg-copy"); copy.delete(); if (copy.exists()) fail();
@Override public void create () { font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); batch = new SpriteBatch(); if (Gdx.files.isExternalStorageAvailable()) { message += "External storage available\n"; message += "External storage path: " + Gdx.files.getExternalStoragePath() + "\n"; InputStream in = Gdx.files.internal("data/cube.obj").read(); StreamUtils.closeQuietly(in); message += "Open internal success\n"; out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external("test.txt").write(false))); out.write("test"); message += "Write external success\n"; InputStream in = Gdx.files.external("test.txt").read(); StreamUtils.closeQuietly(in); message += "Open external success\n"; in = new BufferedReader(new InputStreamReader(Gdx.files.external("test.txt").read())); if (!in.readLine().equals("test")) message += "Read result wrong\n"; if (!Gdx.files.external("test.txt").delete()) message += "Couldn't delete externalstorage/test.txt"; } else { message += "External storage not available"; if (Gdx.files.isLocalStorageAvailable()) {
public static String getDefaultFragmentShader () { if (defaultFragmentShader == null) defaultFragmentShader = Gdx.files.classpath("com/badlogic/gdx/graphics/g3d/shaders/default.fragment.glsl").readString(); return defaultFragmentShader; }
param.packer = new PixmapPacker(1024, 1024, Pixmap.Format.RGBA8888, 2, false, new PixmapPacker.SkylineStrategy()); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/unbom.ttf")); info.overrideMetrics(generatedFont.getData()); BitmapFontWriter.writeFont(generatedFont.getData(), new String[] {"bitmapWrittenFont.png"}, Gdx.files.local("bitmapWrittenFont.fnt"), info, 512, 512); BitmapFontWriter.writePixmaps(param.packer.getPages(), Gdx.files.local(""), "bitmapWrittenFont"); final float ascent = generatedFont.getAscent(); final float descent = generatedFont.getDescent(); final float capHeight = generatedFont.getCapHeight(); final float xHeight = generatedFont.getXHeight(); loadedFont = new BitmapFont(Gdx.files.local("bitmapWrittenFont.fnt")); final float loadedFontascent = loadedFont.getAscent();
@LmlAction("editCustomHotkeys") void editCustomHotkeys() { FileHandle userHotkeyFile = Gdx.files.external(AppConstants.EXTERNAL_DIR + "/hotkeys_user.txt"); if (!userHotkeyFile.exists()) { Gdx.files.internal("hotkeys_user.txt").copyTo(userHotkeyFile); } try { Desktop.getDesktop().open(userHotkeyFile.file()); } catch (IOException e) { Gdx.app.error(TAG, "Error opening " + userHotkeyFile, e); } } @LmlAction public void showMenuFile() {
public void actionPerformed (ActionEvent event) { FileDialog dialog = new FileDialog(editor, "Select Image", FileDialog.LOAD); if (lastDir != null) dialog.setDirectory(lastDir); dialog.setVisible(true); final String file = dialog.getFile(); final String dir = dialog.getDirectory(); if (dir == null || file == null || file.trim().length() == 0) return; lastDir = dir; try { final FileHandle absolute = Gdx.files.absolute(dir + file); final BufferedImage read = ImageIO.read(absolute.read()); final Image scaledInstance = read.getScaledInstance(100, -1, Image.SCALE_SMOOTH); final ImageIcon image = new ImageIcon(scaledInstance); JLabel previewImage = new JLabel(image); previewImage.setOpaque(true); previewImage.setBackground(Color.MAGENTA); buildImagePanel(previewImage, absolute.file()); } catch (IOException e) { e.printStackTrace(); } }
@Override public void create () { Gdx.input.setInputProcessor(new InputAdapter() { public boolean touchDown (int x, int y, int pointer, int newParam) { renderMode = (renderMode + 1) % 6; return false; } }); spriteBatch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); logoSprite = new Sprite(texture); logoSprite.setColor(1, 1, 1, 0.6f); logoSprite.setBounds(50, 100, 400, 100); font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle( "data/verdana39.png", FileType.Internal), false); cache = font.newFontCache(); layout = new GlyphLayout(); }
public void setupShaders () { ShaderProgram.pedantic = false; projTexShader = new ShaderProgram(Gdx.files.internal("data/shaders/projtex-vert.glsl").readString(), Gdx.files.internal( "data/shaders/projtex-frag.glsl").readString()); if (!projTexShader.isCompiled()) throw new GdxRuntimeException("Couldn't compile shader: " + projTexShader.getLog()); }
/** Constructs a new BitmapFont from the given {@link BitmapFontData} and array of {@link TextureRegion}. If the TextureRegion * is null or empty, the image path(s) will be read from the BitmapFontData. The dispose() method will not dispose the texture * of the region(s) if the regions array is != null and not empty. * @param integer If true, rendering positions will be at integer values to avoid filtering artifacts. */ public BitmapFont (BitmapFontData data, Array<TextureRegion> pageRegions, boolean integer) { this.flipped = data.flipped; this.data = data; this.integer = integer; if (pageRegions == null || pageRegions.size == 0) { if (data.imagePaths == null) throw new IllegalArgumentException("If no regions are specified, the font data must have an images path."); // Load each path. int n = data.imagePaths.length; regions = new Array(n); for (int i = 0; i < n; i++) { FileHandle file; if (data.fontFile == null) file = Gdx.files.internal(data.imagePaths[i]); else file = Gdx.files.getFileHandle(data.imagePaths[i], data.fontFile.type()); regions.add(new TextureRegion(new Texture(file, false))); } ownsTexture = true; } else { regions = pageRegions; ownsTexture = false; } cache = newFontCache(); load(data); }
@Override public void create () { camera = new OrthographicCamera(); spriteBatch = new SpriteBatch(); descriptionFont = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true); descriptionFont.setColor(Color.RED); regularTexture = new Texture(Gdx.files.internal("data/verdana39.png"), true); regularFont = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), new TextureRegion(regularTexture), true); regularFont.setColor(COLOR); distanceFieldTexture = new Texture(Gdx.files.internal("data/verdana39distancefield.png"), true); distanceFieldFont = new BitmapFont(Gdx.files.internal("data/verdana39distancefield.fnt"), new TextureRegion( distanceFieldTexture), true); distanceFieldFont.setColor(COLOR); distanceFieldShader = new DistanceFieldShader(); ShaderProgram.pedantic = false; // Useful when debugging this test }
FileHandle file; if (imagePath.equals(ParticleEditor.DEFAULT_PARTICLE) || imagePath.equals(ParticleEditor.DEFAULT_PREMULT_PARTICLE)) { file = Gdx.files.classpath(imagePath); } else { if ((imagePath.contains("/") || imagePath.contains("\\")) && !imageName.contains("..")) { file = Gdx.files.absolute(imagePath); if (!file.exists()) { file = Gdx.files.absolute(new File(effectFile.getParentFile(), imageName).getAbsolutePath()); file = Gdx.files.absolute(new File(effectFile.getParentFile(), imagePath).getAbsolutePath());
private static FileHandle[] getInternalHandles (String... internalPaths) { FileHandle[] handles = new FileHandle[internalPaths.length]; for (int i = 0; i < internalPaths.length; i++) { handles[i] = Gdx.files.internal(internalPaths[i]); } return handles; }
public void setRenderType (RenderType renderType) { this.renderType = renderType; if (renderType != RenderType.FreeType) { if (bitmapFont != null) { bitmapFont.dispose(); generator.dispose(); } } else { String fontFile = getFontFile(); if (fontFile != null) { generator = new FreeTypeFontGenerator(Gdx.files.absolute(fontFile)); FreeTypeFontParameter param = new FreeTypeFontParameter(); param.size = font.getSize(); param.incremental = true; param.flip = true; param.mono = mono; param.gamma = gamma; bitmapFont = generator.generateFont(param); if (bitmapFont.getData().missingGlyph == null) bitmapFont.getData().missingGlyph = bitmapFont.getData().getGlyph('\ufffd'); cache = bitmapFont.newFontCache(); layout = new GlyphLayout(); } } }
/** @param ttfFileRef The file system or classpath location of the TrueTypeFont file. */ static private Font createFont (String ttfFileRef) { try { return Font.createFont(Font.TRUETYPE_FONT, Gdx.files.absolute(ttfFileRef).read()); } catch (FontFormatException ex) { throw new GdxRuntimeException("Invalid font: " + ttfFileRef, ex); } catch (IOException ex) { throw new GdxRuntimeException("Error reading font: " + ttfFileRef, ex); } }