Search in sources :

Example 1 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project netthreads-libgdx by alistairrutherford.

the class TextureCache method load.

/**
	 * Load predefined textures.
	 * 
	 * This requires texture definitions to be added to the {@link AppActorTextures} structure.
	 */
public void load(List<TextureDefinition> textureDefinitions) {
    if (textureAtlas == null) {
        textureAtlas = new TextureAtlas();
    } else {
        dispose();
        textureAtlas = new TextureAtlas();
    }
    for (TextureDefinition definition : textureDefinitions) {
        Texture texture = new Texture(Gdx.files.internal(definition.getPath()));
        TextureRegion textureRegion = new TextureRegion(texture);
        textureAtlas.addRegion(definition.getName(), textureRegion);
        definitions.put(definition.getName(), definition);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Texture(com.badlogic.gdx.graphics.Texture)

Example 2 with TextureAtlas

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

the class RegionInfluencerPanel method initializeComponents.

@Override
protected void initializeComponents() {
    super.initializeComponents();
    JButton pickButton;
    regionSelectDialog = new JDialog(editor, "Pick regions", true);
    regionPickerPanel = new RegionPickerPanel(this);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(regionPickerPanel);
    regionSelectDialog.setContentPane(scrollPane);
    regionSelectDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    addContent(0, 0, pickButton = new JButton("Pick Regions"), false, GridBagConstraints.WEST, GridBagConstraints.NONE);
    pickButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (editor.isUsingDefaultTexture()) {
                JOptionPane.showMessageDialog(editor, "Load a Texture or an Atlas first.");
                return;
            }
            TextureAtlas atlas = editor.getAtlas();
            if (atlas != null)
                regionPickerPanel.setAtlas(atlas);
            else
                regionPickerPanel.setTexture(editor.getTexture());
            regionPickerPanel.revalidate();
            regionPickerPanel.repaint();
            regionSelectDialog.validate();
            regionSelectDialog.repaint();
            regionSelectDialog.pack();
            regionSelectDialog.setVisible(true);
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) JButton(javax.swing.JButton) JDialog(javax.swing.JDialog)

Example 3 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas 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 4 with TextureAtlas

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

the class FilterPerformanceTest method create.

public void create() {
    batch = new SpriteBatch();
    sceneMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    textMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    atlas = new TextureAtlas(Gdx.files.internal("data/issue_pack"), Gdx.files.internal("data/"));
    texture = new Texture(Gdx.files.internal("data/resource1.jpg"), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
    setTextureFilter(0);
    setModeString();
    sprite = atlas.createSprite("map");
    sprite2 = new Sprite(texture, 0, 0, 855, 480);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            mode++;
            if (mode == filters.length * 2)
                mode = 0;
            setTextureFilter(mode / 2);
            setModeString();
            return false;
        }
    });
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 5 with TextureAtlas

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

the class BitmapFontMetricsTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    atlas = new TextureAtlas("data/pack");
    smallFont = new BitmapFont();
    font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), atlas.findRegion("verdana39"), false);
    font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false);
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
}
Also used : TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Aggregations

TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)33 Texture (com.badlogic.gdx.graphics.Texture)11 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)11 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)10 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)7 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 FileHandle (com.badlogic.gdx.files.FileHandle)5 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)4 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)4 Array (com.badlogic.gdx.utils.Array)4 Animation (com.badlogic.gdx.graphics.g2d.Animation)3 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)3 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)3 TexturePacker (com.badlogic.gdx.tools.texturepacker.TexturePacker)3 InputAdapter (com.badlogic.gdx.InputAdapter)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)2 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2