Search in sources :

Example 31 with TextureAtlas

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

the class Assets method setupMouseAnimation.

/** Helper method to setup the mouse animation. */
private void setupMouseAnimation() {
    // Reference used for readability.
    TextureAtlas atlas = manager.get(Assets.GAME_ATLAS_LOCATION, TextureAtlas.class);
    mouseUp = new Animation<TextureRegion>(MOUSE_FRAME_DURATION, atlas.findRegions(Assets.MOUSE + Assets.UP_MODIFIER), PlayMode.LOOP_PINGPONG);
    mouseDown = new Animation<TextureRegion>(MOUSE_FRAME_DURATION, atlas.findRegions(Assets.MOUSE + Assets.DOWN_MODIFIER), PlayMode.LOOP_PINGPONG);
    mouseLeft = new Animation<TextureRegion>(MOUSE_FRAME_DURATION, atlas.findRegions(Assets.MOUSE + Assets.LEFT_MODIFIER), PlayMode.LOOP_PINGPONG);
    mouseRight = new Animation<TextureRegion>(MOUSE_FRAME_DURATION, atlas.findRegions(Assets.MOUSE + Assets.RIGHT_MODIFIER), PlayMode.LOOP_PINGPONG);
    assert mouseUp.getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseUp frame count does not match MOUSE_FRAME_COUNT.";
    assert mouseDown.getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseDown frame count does not match MOUSE_FRAME_COUNT.";
    assert mouseLeft.getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseLeft frame count does not match MOUSE_FRAME_COUNT.";
    assert mouseRight.getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseRight frame count does not match MOUSE_FRAME_COUNT.";
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas)

Example 32 with TextureAtlas

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

the class Assets method loadMapResources.

/** Helper method for loading the map resources. */
private void loadMapResources() {
    manager.load(GAME_ATLAS_LOCATION, TextureAtlas.class);
    manager.finishLoadingAsset(GAME_ATLAS_LOCATION);
    // Reference used for readability.
    TextureAtlas atlas = manager.get(Assets.GAME_ATLAS_LOCATION, TextureAtlas.class);
    tiles = new TiledMapTileSet();
    StaticTiledMapTile background = new StaticTiledMapTile(atlas.findRegion(BACKGROUND));
    StaticTiledMapTile barrier = new StaticTiledMapTile(atlas.findRegion(BARRIER));
    StaticTiledMapTile placeholder = new StaticTiledMapTile(atlas.findRegion(PLACEHOLDER));
    background.setId(TileIDs.computeID(TileIDs.BACKGROUND));
    barrier.setId(TileIDs.computeID(TileIDs.BARRIER));
    placeholder.setId(TileIDs.computeID(TileIDs.PLACEHOLDER));
    tiles.putTile(background.getId(), background);
    tiles.putTile(barrier.getId(), barrier);
    tiles.putTile(placeholder.getId(), placeholder);
    StaticTiledMapTile verticalOn = new StaticTiledMapTile(atlas.findRegion(VERTICAL + ON_MODIFIER));
    StaticTiledMapTile verticalOff = new StaticTiledMapTile(atlas.findRegion(VERTICAL + OFF_MODIFIER));
    StaticTiledMapTile verticalUnknown = new StaticTiledMapTile(atlas.findRegion(VERTICAL + UNKNOWN_MODIFIER));
    verticalOn.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, TileIDs.ON));
    verticalOff.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, TileIDs.OFF));
    verticalUnknown.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.VERTICAL, TileIDs.UNKNOWN));
    tiles.putTile(verticalOn.getId(), verticalOn);
    tiles.putTile(verticalOff.getId(), verticalOff);
    tiles.putTile(verticalUnknown.getId(), verticalUnknown);
    loadGates(atlas, ON_MODIFIER, UP_MODIFIER, TileIDs.ON, TileIDs.UP_GATE);
    loadGates(atlas, ON_MODIFIER, DOWN_MODIFIER, TileIDs.ON, TileIDs.DOWN_GATE);
    loadGates(atlas, OFF_MODIFIER, UP_MODIFIER, TileIDs.OFF, TileIDs.UP_GATE);
    loadGates(atlas, OFF_MODIFIER, DOWN_MODIFIER, TileIDs.OFF, TileIDs.DOWN_GATE);
    loadGates(atlas, UNKNOWN_MODIFIER, UP_MODIFIER, TileIDs.UNKNOWN, TileIDs.UP_GATE);
    loadGates(atlas, UNKNOWN_MODIFIER, DOWN_MODIFIER, TileIDs.UNKNOWN, TileIDs.DOWN_GATE);
    StaticTiledMapTile turnOnUpLeft = new StaticTiledMapTile(atlas.findRegion(TURN + ON_MODIFIER + UP_MODIFIER + LEFT_MODIFIER));
    StaticTiledMapTile turnOffUpLeft = new StaticTiledMapTile(atlas.findRegion(TURN + OFF_MODIFIER + UP_MODIFIER + LEFT_MODIFIER));
    StaticTiledMapTile turnOnUpRight = new StaticTiledMapTile(atlas.findRegion(TURN + ON_MODIFIER + UP_MODIFIER + RIGHT_MODIFIER));
    StaticTiledMapTile turnOffUpRight = new StaticTiledMapTile(atlas.findRegion(TURN + OFF_MODIFIER + UP_MODIFIER + RIGHT_MODIFIER));
    StaticTiledMapTile turnOnDownLeft = new StaticTiledMapTile(atlas.findRegion(TURN + ON_MODIFIER + DOWN_MODIFIER + LEFT_MODIFIER));
    StaticTiledMapTile turnOffDownLeft = new StaticTiledMapTile(atlas.findRegion(TURN + OFF_MODIFIER + DOWN_MODIFIER + LEFT_MODIFIER));
    StaticTiledMapTile turnOnDownRight = new StaticTiledMapTile(atlas.findRegion(TURN + ON_MODIFIER + DOWN_MODIFIER + RIGHT_MODIFIER));
    StaticTiledMapTile turnOffDownRight = new StaticTiledMapTile(atlas.findRegion(TURN + OFF_MODIFIER + DOWN_MODIFIER + RIGHT_MODIFIER));
    turnOnUpLeft.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.ON, TileIDs.UP_LEFT));
    turnOffUpLeft.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.OFF, TileIDs.UP_LEFT));
    turnOnUpRight.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.ON, TileIDs.UP_RIGHT));
    turnOffUpRight.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.OFF, TileIDs.UP_RIGHT));
    turnOnDownLeft.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.ON, TileIDs.DOWN_LEFT));
    turnOffDownLeft.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.OFF, TileIDs.DOWN_LEFT));
    turnOnDownRight.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.ON, TileIDs.DOWN_RIGHT));
    turnOffDownRight.setId(TileIDs.computeID(TileIDs.WIRE_RANGE, TileIDs.TURN, TileIDs.OFF, TileIDs.DOWN_RIGHT));
    tiles.putTile(turnOnUpLeft.getId(), turnOnUpLeft);
    tiles.putTile(turnOffUpLeft.getId(), turnOffUpLeft);
    tiles.putTile(turnOnUpRight.getId(), turnOnUpRight);
    tiles.putTile(turnOffUpRight.getId(), turnOffUpRight);
    tiles.putTile(turnOnDownLeft.getId(), turnOnDownLeft);
    tiles.putTile(turnOffDownLeft.getId(), turnOffDownLeft);
    tiles.putTile(turnOnDownRight.getId(), turnOnDownRight);
    tiles.putTile(turnOffDownRight.getId(), turnOffDownRight);
    loadFish(atlas, BLUE_MODIFIER, TileIDs.BLUE);
    loadFish(atlas, PURPLE_MODIFIER, TileIDs.PURPLE);
    loadFish(atlas, GREEN_MODIFIER, TileIDs.GREEN);
    loadFish(atlas, RED_MODIFIER, TileIDs.RED);
    loadFish(atlas, ORANGE_MODIFIER, TileIDs.ORANGE);
    StaticTiledMapTile cheese = new StaticTiledMapTile(atlas.findRegion(CHEESE));
    cheese.setId(TileIDs.computeID(TileIDs.POWERUP_RANGE, TileIDs.CHEESE));
    tiles.putTile(cheese.getId(), cheese);
}
Also used : TiledMapTileSet(com.badlogic.gdx.maps.tiled.TiledMapTileSet) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)

Example 33 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project gdx-skineditor by cobolfoo.

the class NinePatchEditorDialog method refreshPreview.

public void refreshPreview() {
    Gdx.app.log("NinePatchEditorDialog", "refresh preview.");
    Pixmap pixmapImage = new Pixmap(Gdx.files.internal(textSourceImage.getText()));
    Pixmap pixmap = new Pixmap((int) (pixmapImage.getWidth() + 2), (int) (pixmapImage.getHeight() + 2), Pixmap.Format.RGBA8888);
    pixmap.drawPixmap(pixmapImage, 1, 1);
    pixmap.setColor(Color.BLACK);
    // Range left
    int h = pixmapImage.getHeight() + 1;
    pixmap.drawLine(0, (int) (h * rangeLeft.rangeStart), 0, (int) (h * rangeLeft.rangeStop));
    // Range top
    int w = pixmapImage.getWidth() + 1;
    pixmap.drawLine((int) (w * rangeTop.rangeStart), 0, (int) (w * rangeTop.rangeStop), 0);
    // Range right
    h = pixmapImage.getHeight() + 1;
    pixmap.drawLine(pixmapImage.getWidth() + 1, (int) (h * rangeRight.rangeStart), pixmapImage.getWidth() + 1, (int) (h * rangeRight.rangeStop));
    // Range bottom
    w = pixmapImage.getWidth() + 1;
    pixmap.drawLine((int) (w * rangeBottom.rangeStart), pixmap.getHeight() - 1, (int) (w * rangeBottom.rangeStop), pixmap.getHeight() - 1);
    PixmapIO.writePNG(tmpFile, pixmap);
    pixmapImage.dispose();
    pixmap.dispose();
    FileHandle fh = new FileHandle(System.getProperty("java.io.tmpdir")).child("skin_ninepatch");
    TexturePacker.Settings settings = new TexturePacker.Settings();
    TexturePacker.process(settings, fh.path(), fh.path(), "pack");
    TextureAtlas ta = new TextureAtlas(fh.child("pack.atlas"));
    NinePatch np = ta.createPatch("button");
    NinePatchDrawable drawable = new NinePatchDrawable(np);
    reviewTablePreview();
    buttonPreview1.getStyle().up = drawable;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) TexturePacker(com.badlogic.gdx.tools.texturepacker.TexturePacker) Pixmap(com.badlogic.gdx.graphics.Pixmap) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

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