Search in sources :

Example 1 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class FreetypeFontLoader method loadSync.

@Override
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, FreeTypeFontLoaderParameter parameter) {
    if (parameter == null)
        throw new RuntimeException("FreetypeFontParameter must be set in AssetManager#load to point at a TTF file!");
    FreeTypeFontGenerator generator = manager.get(parameter.fontFileName + ".gen", FreeTypeFontGenerator.class);
    BitmapFont font = generator.generateFont(parameter.fontParameters);
    return font;
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 2 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class BitmapFontLoader method loadSync.

@Override
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) {
    if (parameter != null && parameter.atlasName != null) {
        TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class);
        String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString();
        AtlasRegion region = atlas.findRegion(name);
        if (region == null)
            throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName);
        return new BitmapFont(file, region);
    } else {
        int n = data.getImagePaths().length;
        Array<TextureRegion> regs = new Array(n);
        for (int i = 0; i < n; i++) {
            regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class)));
        }
        return new BitmapFont(data, regs, true);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 3 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class DragAndDropTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    final Skin skin = new Skin();
    skin.add("default", new LabelStyle(new BitmapFont(), Color.WHITE));
    skin.add("badlogic", new Texture("data/badlogic.jpg"));
    Image sourceImage = new Image(skin, "badlogic");
    sourceImage.setBounds(50, 125, 100, 100);
    stage.addActor(sourceImage);
    Image validTargetImage = new Image(skin, "badlogic");
    validTargetImage.setBounds(200, 50, 100, 100);
    stage.addActor(validTargetImage);
    Image invalidTargetImage = new Image(skin, "badlogic");
    invalidTargetImage.setBounds(200, 200, 100, 100);
    stage.addActor(invalidTargetImage);
    DragAndDrop dragAndDrop = new DragAndDrop();
    dragAndDrop.addSource(new Source(sourceImage) {

        public Payload dragStart(InputEvent event, float x, float y, int pointer) {
            Payload payload = new Payload();
            payload.setObject("Some payload!");
            payload.setDragActor(new Label("Some payload!", skin));
            Label validLabel = new Label("Some payload!", skin);
            validLabel.setColor(0, 1, 0, 1);
            payload.setValidDragActor(validLabel);
            Label invalidLabel = new Label("Some payload!", skin);
            invalidLabel.setColor(1, 0, 0, 1);
            payload.setInvalidDragActor(invalidLabel);
            return payload;
        }
    });
    dragAndDrop.addTarget(new Target(validTargetImage) {

        public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
            getActor().setColor(Color.GREEN);
            return true;
        }

        public void reset(Source source, Payload payload) {
            getActor().setColor(Color.WHITE);
        }

        public void drop(Source source, Payload payload, float x, float y, int pointer) {
            System.out.println("Accepted: " + payload.getObject() + " " + x + ", " + y);
        }
    });
    dragAndDrop.addTarget(new Target(invalidTargetImage) {

        public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
            getActor().setColor(Color.RED);
            return false;
        }

        public void reset(Source source, Payload payload) {
            getActor().setColor(Color.WHITE);
        }

        public void drop(Source source, Payload payload, float x, float y, int pointer) {
        }
    });
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) Source(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Source) Target(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Target) DragAndDrop(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Payload(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Payload) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 4 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class ETC1Test method create.

@Override
public void create() {
    font = new BitmapFont();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    controller = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(controller);
    Pixmap pixmap = new Pixmap(32, 32, Format.RGB565);
    pixmap.setColor(1, 0, 0, 1);
    pixmap.fill();
    pixmap.setColor(0, 1, 0, 1);
    pixmap.drawLine(0, 0, 32, 32);
    pixmap.drawLine(0, 32, 32, 0);
    ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap);
    pixmap.dispose();
    pixmap = ETC1.decodeImage(encodedImage, Format.RGB565);
    encodedImage.dispose();
    img1 = new Texture(pixmap);
    img2 = new Texture("data/test.etc1");
    batch = new SpriteBatch();
    pixmap.dispose();
}
Also used : ETC1Data(com.badlogic.gdx.graphics.glutils.ETC1.ETC1Data) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 5 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class FilesTest method create.

@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";
        try {
            InputStream in = Gdx.files.internal("data/cube.obj").read();
            StreamUtils.closeQuietly(in);
            message += "Open internal success\n";
        } catch (Throwable e) {
            message += "Couldn't open internal data/cube.obj\n" + e.getMessage() + "\n";
        }
        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external("test.txt").write(false)));
            out.write("test");
            message += "Write external success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open externalstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't write externalstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(out);
        }
        try {
            InputStream in = Gdx.files.external("test.txt").read();
            StreamUtils.closeQuietly(in);
            message += "Open external success\n";
        } catch (Throwable e) {
            message += "Couldn't open internal externalstorage/test.txt\n" + e.getMessage() + "\n";
        }
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(Gdx.files.external("test.txt").read()));
            if (!in.readLine().equals("test"))
                message += "Read result wrong\n";
            else
                message += "Read external success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open externalstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't read externalstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(in);
        }
        if (!Gdx.files.external("test.txt").delete())
            message += "Couldn't delete externalstorage/test.txt";
    } else {
        message += "External storage not available";
    }
    if (Gdx.files.isLocalStorageAvailable()) {
        message += "Local storage available\n";
        message += "Local storage path: " + Gdx.files.getLocalStoragePath() + "\n";
        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(Gdx.files.local("test.txt").write(false)));
            out.write("test");
            message += "Write local success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open localstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't write localstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(out);
        }
        try {
            InputStream in = Gdx.files.local("test.txt").read();
            StreamUtils.closeQuietly(in);
            message += "Open local success\n";
        } catch (Throwable e) {
            message += "Couldn't open localstorage/test.txt\n" + e.getMessage() + "\n";
        }
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(Gdx.files.local("test.txt").read()));
            if (!in.readLine().equals("test"))
                message += "Read result wrong\n";
            else
                message += "Read local success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open localstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't read localstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(in);
        }
        try {
            byte[] testBytes = Gdx.files.local("test.txt").readBytes();
            if (Arrays.equals("test".getBytes(), testBytes))
                message += "Read into byte array success\n";
            else
                fail();
        } catch (Throwable e) {
            message += "Couldn't read localstorage/test.txt\n" + e.getMessage() + "\n";
        }
        if (!Gdx.files.local("test.txt").delete())
            message += "Couldn't delete localstorage/test.txt";
    }
    try {
        testClasspath();
        testInternal();
        testExternal();
        testAbsolute();
        testLocal();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BufferedWriter(java.io.BufferedWriter)

Aggregations

BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)104 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)64 Texture (com.badlogic.gdx.graphics.Texture)31 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)21 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)16 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)12 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)11 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)10 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)10 AssetManager (com.badlogic.gdx.assets.AssetManager)9 Color (com.badlogic.gdx.graphics.Color)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 InputAdapter (com.badlogic.gdx.InputAdapter)7 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 Pixmap (com.badlogic.gdx.graphics.Pixmap)6 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)6