Search in sources :

Example 96 with BitmapFont

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

the class ViewportTest2 method create.

public void create() {
    font = new BitmapFont();
    font.setColor(0, 0, 0, 1);
    Pixmap pixmap = new Pixmap(16, 16, Format.RGBA8888);
    pixmap.setColor(1, 1, 1, 1);
    pixmap.fill();
    texture = new Texture(pixmap);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    camera.position.set(100, 100, 0);
    camera.update();
    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();
    names = ViewportTest1.getViewportNames();
    name = names.first();
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}
Also used : InputAdapter(com.badlogic.gdx.InputAdapter) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) 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 97 with BitmapFont

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

the class YDownTest method create.

@Override
public void create() {
    // a bitmap font to draw some text, note that we
    // pass true to the constructor, which flips glyphs on y
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true);
    // a texture region, note the flipping on y again
    region = new TextureRegion(new Texture("data/badlogic.jpg"));
    region.flip(false, true);
    // a texture atlas, note the boolean
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"), true);
    // a sprite, created from a region in the atlas
    sprite = atlas.createSprite("badlogicsmall");
    sprite.setPosition(0, 0);
    // a sprite batch with which we want to render
    batch = new SpriteBatch();
    // a camera, note the setToOrtho call, which will set the y-axis
    // to point downwards
    camera = new OrthographicCamera();
    camera.setToOrtho(true);
    // a stage which uses our y-down camera and a simple actor (see MyActor below),
    // which uses the flipped region. The key here is to
    // set our y-down camera on the stage, the rest is just for demo purposes.
    stage = new Stage();
    stage.getViewport().setCamera(camera);
    image = new MyActor(region);
    image.setPosition(100, 100);
    stage.addActor(image);
    // finally we write up the stage as the input process and call it a day.
    Gdx.input.setInputProcessor(stage);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Stage(com.badlogic.gdx.scenes.scene2d.Stage) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 98 with BitmapFont

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

the class TextInputDialogTest method create.

public void create() {
    message = "Touch screen for dialog";
    batch = new SpriteBatch();
    font = new BitmapFont();
    Gdx.input.getTextInput(new TextInputListener() {

        @Override
        public void input(String text) {
            message = "message: " + text + ", touch screen for new dialog";
        }

        @Override
        public void canceled() {
            message = "cancled by user";
        }
    }, "enter something funny", "funny", "something funny");
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) TextInputListener(com.badlogic.gdx.Input.TextInputListener)

Example 99 with BitmapFont

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

the class TextureDownloadTest method create.

@Override
public void create() {
    new Thread(new Runnable() {

        /** Downloads the content of the specified url to the array. The array has to be big enough. */
        private int download(byte[] out, String url) {
            InputStream in = null;
            try {
                HttpURLConnection conn = null;
                conn = (HttpURLConnection) new URL(url).openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(false);
                conn.setUseCaches(true);
                conn.connect();
                in = conn.getInputStream();
                int readBytes = 0;
                while (true) {
                    int length = in.read(out, readBytes, out.length - readBytes);
                    if (length == -1)
                        break;
                    readBytes += length;
                }
                return readBytes;
            } catch (Exception ex) {
                return 0;
            } finally {
                StreamUtils.closeQuietly(in);
            }
        }

        @Override
        public void run() {
            // assuming the content is not bigger than 200kb.
            byte[] bytes = new byte[200 * 1024];
            int numBytes = download(bytes, "http://www.badlogicgames.com/wordpress/wp-content/uploads/2012/01/badlogic-new.png");
            if (numBytes != 0) {
                // load the pixmap, make it a power of two if necessary (not needed for GL ES 2.0!)
                Pixmap pixmap = new Pixmap(bytes, 0, numBytes);
                final int originalWidth = pixmap.getWidth();
                final int originalHeight = pixmap.getHeight();
                int width = MathUtils.nextPowerOfTwo(pixmap.getWidth());
                int height = MathUtils.nextPowerOfTwo(pixmap.getHeight());
                final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
                potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
                pixmap.dispose();
                Gdx.app.postRunnable(new Runnable() {

                    @Override
                    public void run() {
                        image = new TextureRegion(new Texture(potPixmap), 0, 0, originalWidth, originalHeight);
                    }
                });
            }
        }
    }).start();
    font = new BitmapFont();
    batch = new SpriteBatch();
}
Also used : InputStream(java.io.InputStream) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) URL(java.net.URL) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) HttpURLConnection(java.net.HttpURLConnection) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 100 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project Alkahest-Coffee by AlkahestDev.

the class MainGame method create.

@Override
public void create() {
    Gdx.graphics.setCursor(Gdx.graphics.newCursor(new Pixmap(Gdx.files.internal("mouseCursorTemp.png")), 0, 0));
    assetManager = new AssetManager();
    queueLoading();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.translate(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    camera.update();
    //viewport = new FitViewport(1920, 1080, camera);
    fontCaches = new Array<BitmapFontCache>();
    BitmapFont dagger20 = new BitmapFont(Gdx.files.internal("fonts/dagger20.fnt"));
    BitmapFont dagger30 = new BitmapFont(Gdx.files.internal("fonts/dagger30.fnt"));
    BitmapFont dagger40 = new BitmapFont(Gdx.files.internal("fonts/dagger40.fnt"));
    BitmapFont dagger50 = new BitmapFont(Gdx.files.internal("fonts/dagger50.fnt"));
    dagger20.getData().markupEnabled = true;
    dagger30.getData().markupEnabled = true;
    dagger40.getData().markupEnabled = true;
    dagger50.getData().markupEnabled = true;
    fontCaches.add(new BitmapFontCache(dagger20));
    fontCaches.add(new BitmapFontCache(dagger30));
    fontCaches.add(new BitmapFontCache(dagger40));
    fontCaches.add(new BitmapFontCache(dagger50));
    shapeRenderer = new ShapeRenderer();
    gameMain = new MainMenu(fontCaches, assetManager, camera);
    loadingMenu = new LoadingMenu(fontCaches, assetManager, camera);
    connectingMenu = new ConnectingMenu(fontCaches, assetManager, camera);
    serverBrowser = new ServerBrowser(fontCaches, assetManager, camera);
    settingsMenu = new SettingsMenu(fontCaches, assetManager, camera);
    pickingInfoMenu = new ClientPickingInfoMenu(fontCaches, assetManager, camera);
    lobbyMenu = new ClientLobbyMenu(fontCaches, assetManager, camera);
    // loadingmenu is the only one that is setup before anything else is loaded, background frames are loaded and added to it here
    setupLoadingMenu();
    scW = Gdx.graphics.getWidth();
    scH = Gdx.graphics.getHeight();
    //System.out.println(new Pixmap(Gdx.files.internal("pixmapTest.png")).getPixel(0,0)>>8);//since gimp doesn't do alpha in a friendly way, I'll bitshift right 8 bits to ignore alpha
    state = GameState.State.LOADINGGAME;
    batch = new SpriteBatch();
    client = new MultiplayerClient();
    clientSoldier = new PlayerSoldier(new Rectangle(0, 0, 1, 2), 0, "");
    client.startClient();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    menu = new UniversalClientMenu(fontCaches, assetManager, camera);
    Gdx.input.setInputProcessor(this);
}
Also used : MultiplayerClient(me.dumfing.multiplayerTools.MultiplayerClient) AssetManager(com.badlogic.gdx.assets.AssetManager) Rectangle(com.badlogic.gdx.math.Rectangle) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

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