Example usage for com.badlogic.gdx.graphics.g2d TextureAtlas getRegions

List of usage examples for com.badlogic.gdx.graphics.g2d TextureAtlas getRegions

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d TextureAtlas getRegions.

Prototype

public Array<AtlasRegion> getRegions() 

Source Link

Document

Returns all regions in the atlas.

Usage

From source file:com.a2client.gui.Skin.java

License:Open Source License

public void ParseIcons() {
    TextureAtlas atlas = Main.getAssetManager().get(RESOURCE_DIR + "icons.pack", TextureAtlas.class);

    Array<AtlasRegion> regions = atlas.getRegions();

    for (AtlasRegion r : regions) {
        SkinElement el;//from  w w  w  .j  av a2  s  . c om
        // ?  ? - ? ,     ? ?  ?
        el = new SkinElement(this, r.name, r, r.originalWidth, r.originalHeight, new Rect(0, 0, 0, 0));
        AddStatesCenter(el, r.packedHeight, r.packedWidth, 0, 0);
    }
}

From source file:com.bladecoder.engine.model.AtlasRenderer.java

License:Apache License

@Override
public String[] getInternalAnimations(AnimationDesc anim) {
    retrieveSource(anim.source);/*  www .  j  a  v  a 2  s  .co  m*/

    TextureAtlas atlas = EngineAssetManager.getInstance().getTextureAtlas(anim.source);

    Array<AtlasRegion> animations = atlas.getRegions();
    ArrayList<String> l = new ArrayList<String>();

    for (int i = 0; i < animations.size; i++) {
        AtlasRegion a = animations.get(i);
        if (!l.contains(a.name))
            l.add(a.name);
    }

    return l.toArray(new String[l.size()]);
}

From source file:com.dongbat.game.util.factory.UnitFactory.java

public static Entity createQueen(World world, Vector2 position, float radius) {
    Entity e = world.createEntity(UUID.randomUUID());

    Stats stats = new Stats();
    stats.setAllowComsumming(false);//from   w  w  w .  j a v  a  2 s  .  c  o m
    stats.setConsumable(true);
    stats.setBaseRateSpeed(2000);

    BuffComponent buff = new BuffComponent();

    Physics physics = new Physics();
    physics.setBody(PhysicsUtil.createBody(PhysicsUtil.getPhysicsWorld(world), position, radius, e));
    physics.getBody().setUserData(UuidUtil.getUuid(e));

    UnitMovement movement = new UnitMovement();

    float posX = (float) (ECSUtil.getRandom(world).getFloat(-1, 1) * scaleX);
    float posY = (float) (ECSUtil.getRandom(world).getFloat(-1, 1) * scaleY);
    movement.setDirectionVelocity(new Vector2(posX, posY));

    Display display = new Display();

    e.edit().add(physics).add(stats).add(new CollisionComponent()).add(buff).add(new Queen())
            .add(new Detection()).add(movement).add(display);

    BuffUtil.addBuff(world, e, e, "QueenTeleportSchedule", -1, 1);
    BuffUtil.addBuff(world, e, e, "ProduceFoodSchedule", -1, 1);
    BuffUtil.addBuff(world, e, e, "FeedSmaller", -1, 1, "feedPerSecond", 0.2f);
    BuffUtil.addBuff(world, e, e, "SelfDefense", -1, 1, "framePerFood", 10);
    BuffUtil.addBuff(world, e, e, "QueenGrowth", -1, 1, "cap", 20);
    display.setPosition(PhysicsUtil.getPosition(world, e));
    display.setRadius(PhysicsUtil.getRadius(world, e));
    display.setRotation(EntityUtil.getComponent(world, e, UnitMovement.class).getDirectionVelocity().angle());
    TextureAtlas queen = AssetUtil.getUnitAtlas().get("queen");
    Animation animation = new Animation(0.1f, queen.getRegions());
    animation.setPlayMode(Animation.PlayMode.LOOP);
    display.setDefaultAnimation(new AnimatedSprite(animation));
    return e;
}

From source file:com.forerunnergames.peril.client.ui.screens.game.play.modes.classic.playmap.io.loaders.DefaultCountryImagesFactory.java

License:Open Source License

@Override
public void create(final PlayMapMetadata playMapMetadata, final ImmutableList<TextureAtlas> countryAtlases) {
    Arguments.checkIsNotNull(playMapMetadata, "playMapMetadata");
    Arguments.checkIsNotNull(countryAtlases, "countryAtlases");
    Arguments.checkHasNoNullElements(countryAtlases, "countryAtlases");

    log.debug("Creating country images for play map [{}]...", playMapMetadata);

    destroy();/*w ww  .  j  ava 2  s . co  m*/

    int atlasIndex = 0;

    for (final TextureAtlas countryAtlas : countryAtlases) {
        for (final TextureAtlas.AtlasRegion countryAtlasRegion : countryAtlas.getRegions()) {
            final ImmutableList<String> regionNameSegments = createRegionNameSegments(countryAtlasRegion,
                    playMapMetadata);
            final String countryName = createCountryNameFrom(regionNameSegments);
            final SpriteDrawable countryDrawable = new SpriteDrawable(
                    countryAtlas.createSprite(countryAtlasRegion.name));

            if (containsImageState(CountryPrimaryImageState.class, regionNameSegments)) {
                final CountryPrimaryImageState countryPrimaryImageState = createCountryImageStateFrom(
                        CountryPrimaryImageState.class, regionNameSegments);
                final CountryPrimaryImage countryPrimaryImage = new CountryPrimaryImage(countryDrawable,
                        countryName, countryPrimaryImageState);
                countryNamesAndPrimaryImageStatesToPrimaryImages.put(countryName, countryPrimaryImageState,
                        countryPrimaryImage);
            } else if (containsImageState(CountrySecondaryImageState.class, regionNameSegments)) {
                final CountrySecondaryImageState countrySecondaryImageState = createCountryImageStateFrom(
                        CountrySecondaryImageState.class, regionNameSegments);
                final CountrySecondaryImage countrySecondaryImage = new CountrySecondaryImage(countryDrawable,
                        countryName, countrySecondaryImageState);
                countryNamesAndSecondaryImageStatesToSecondaryImages.put(countryName,
                        countrySecondaryImageState, countrySecondaryImage);
            } else {
                invalidCountryImageState(regionNameSegments, countryAtlasRegion, playMapMetadata);
            }

            registerCountryAtlasIndex(countryName, atlasIndex);
        }

        ++atlasIndex;
    }

    for (final String countryName : countryNamesAndPrimaryImageStatesToPrimaryImages.rowKeySet()) {
        countryNamesToPrimaryImages.put(countryName,
                new CountryPrimaryImages(
                        ImmutableMap.copyOf(countryNamesAndPrimaryImageStatesToPrimaryImages.row(countryName)),
                        countryNamesToAtlasIndices.get(countryName)));
    }

    for (final String countryName : countryNamesAndSecondaryImageStatesToSecondaryImages.rowKeySet()) {
        countryNamesAndSecondaryImageStatesToSecondaryImages.put(countryName, CountrySecondaryImageState.NONE,
                new CountrySecondaryImage(null, countryName, CountrySecondaryImageState.NONE));
    }

    for (final String countryName : countryNamesAndSecondaryImageStatesToSecondaryImages.rowKeySet()) {
        countryNamesToSecondaryImages.put(countryName,
                new CountrySecondaryImages(
                        ImmutableMap
                                .copyOf(countryNamesAndSecondaryImageStatesToSecondaryImages.row(countryName)),
                        countryNamesToAtlasIndices.get(countryName)));
    }

    loadedPlayMapMetadata = playMapMetadata;

    log.debug("Finished creating country images for play map [{}].", playMapMetadata);
}

From source file:com.johnogel.astrobros.gameobjects.AstroBro.java

public void initializeAnimation(TextureAtlas atlas) {
    float time = MathUtils.random.nextFloat() * 6;
    animation = new Animation(1 / 48f, atlas.getRegions());
    AnimatedSprite a = new AnimatedSprite(animation);
    animated_sprite = new AnimatedBox2DSprite(a);
    animated_sprite.setTime(time);//from  www.j a  va  2 s. co  m

    animated_sprite.setPlaying(true);
    //animated_sprite.setAutoUpdate(true);

    //body.setUserData(animated_sprite);
}

From source file:com.kotcrab.vis.editor.module.project.assetsmanager.TextureAtlasViewTab.java

License:Apache License

public TextureAtlasViewTab(String relativeAtlasPath, TextureAtlas atlas, String name) {
    super(false, true);
    this.name = name;

    filesView = new GridGroup(92, 4);

    SearchField searchField = new SearchField(newText -> {
        filesView.clear();/*from  ww  w .j  a va2s .  c  o m*/

        for (AtlasItem item : items) {
            if (item.getRegion().name.contains(newText))
                filesView.addActor(item);
        }

        if (filesView.getChildren().size == 0)
            return false;
        else
            return true;
    });

    VisTable topTable = new VisTable(true);
    topTable.add(name);
    topTable.add().expand().fill();
    topTable.add(searchField).right().row();

    VisScrollPane scrollPane = new VisScrollPane(filesView);
    scrollPane.setFlickScroll(false);
    scrollPane.setScrollingDisabled(true, false);

    contentTable = new VisTable();
    contentTable.setBackground(VisUI.getSkin().getDrawable("window-bg"));
    contentTable.add(topTable).expandX().fillX().pad(3).row();
    contentTable.addSeparator().pad(0);
    contentTable.add(scrollPane).expand().fill();

    Array<AtlasRegion> regions = atlas.getRegions();

    for (AtlasRegion region : regions) {
        AtlasItem item = new AtlasItem(relativeAtlasPath, region);
        items.add(item);
        filesView.addActor(item);
    }
}

From source file:com.o2d.pkayjava.editor.utils.ImportUtils.java

License:Apache License

public static int checkFileTypeByContent(String path) {
    File file = new File(path);
    long fileSizeInBytes = file.length();
    // Convert the bytes to Kilobytes (1 KB = 1024 Bytes)
    long fileSizeInKB = fileSizeInBytes / 1024;

    if (fileSizeInKB > 200) {
        return TYPE_UNCKNOWN;
    }/*w ww. j  a  v  a 2 s .c o  m*/

    int type = TYPE_UNCKNOWN;

    try {
        String contents = FileUtils.readFileToString(file);

        // checking for atlas file
        if (contents.contains("format: ") && contents.contains("filter: ") && contents.contains("xy: ")) {
            type = TYPE_TEXTURE_ATLAS;
            // need to figure out if atlas is animation or just files.
            TextureAtlas atlas = new TextureAtlas(new FileHandle(file));
            String[] regionNames = new String[atlas.getRegions().size];
            for (int i = 0; i < atlas.getRegions().size; i++) {
                regionNames[i] = atlas.getRegions().get(i).name;
            }
            boolean isSequence = isAnimationSequence(regionNames);

            if (isSequence) {
                type = TYPE_SPRITE_ANIMATION_ATLAS;
            }

            return type;
        }

        // checking for spine animation
        if (contents.contains("\"skeleton\":{\"")) {
            type = TYPE_SPINE_ANIMATION;
            return type;
        }

        // checking for particle effect
        if (contents.contains("- Options - ") && contents.contains("- Image Path -")
                && contents.contains("- Duration -")) {
            type = TYPE_PARTICLE_EFFECT;
            return type;
        }

    } catch (IOException e) {
    }

    return type;
}

From source file:com.o2d.pkayjava.editor.view.ui.box.resourcespanel.UIImagesTabMediator.java

License:Apache License

@Override
protected void initList(String searchText) {
    Sandbox sandbox = Sandbox.getInstance();
    ResourceManager resourceManager = facade.retrieveProxy(ResourceManager.NAME);

    TextureAtlas atlas = resourceManager.getProjectAssetsList();

    Array<DraggableResource> thumbnailBoxes = new Array<>();
    Array<TextureAtlas.AtlasRegion> atlasRegions = atlas.getRegions();
    for (TextureAtlas.AtlasRegion region : atlasRegions) {
        if (!region.name.contains(searchText))
            continue;
        boolean is9patch = region.splits != null;
        DraggableResource draggableResource = new DraggableResource(new ImageResource(region));
        if (is9patch) {
            draggableResource.setFactoryFunction(ItemFactory.get()::create9Patch);
        } else {//w ww .  j av  a  2s .c o  m
            draggableResource.setFactoryFunction(ItemFactory.get()::createSimpleImage);
        }
        draggableResource.initDragDrop();
        thumbnailBoxes.add(draggableResource);
    }

    viewComponent.setThumbnailBoxes(thumbnailBoxes);
}

From source file:com.ray3k.skincomposer.data.AtlasData.java

License:Open Source License

public void readAtlas(FileHandle fileHandle) throws Exception {
    if (fileHandle.exists()) {
        FileHandle saveFile = main.getProjectData().getSaveFile();
        FileHandle targetDirectory;/*from  www  . j ava  2 s. com*/
        if (saveFile != null) {
            targetDirectory = saveFile.sibling(saveFile.nameWithoutExtension() + "_data/");
        } else {
            targetDirectory = Gdx.files.local("temp/" + main.getProjectData().getId() + "_data/");
        }

        targetDirectory.mkdirs();

        TextureAtlas atlas = new TextureAtlas(fileHandle);
        Array<AtlasRegion> regions = atlas.getRegions();

        for (AtlasRegion region : regions) {
            Texture texture = region.getTexture();
            if (!texture.getTextureData().isPrepared()) {
                texture.getTextureData().prepare();
            }
            Pixmap.setBlending(Pixmap.Blending.None);
            Pixmap pixmap = texture.getTextureData().consumePixmap();
            Pixmap savePixmap;
            String name;

            if (region.splits == null && region.pads == null) {
                name = region.name + ".png";
                savePixmap = new Pixmap(region.getRegionWidth(), region.getRegionHeight(),
                        Pixmap.Format.RGBA8888);
                for (int x = 0; x < region.getRegionWidth(); x++) {
                    for (int y = 0; y < region.getRegionHeight(); y++) {
                        int colorInt = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y);
                        savePixmap.drawPixel(x, y, colorInt);
                    }
                }
            } else {
                name = region.name + ".9.png";
                savePixmap = new Pixmap(region.getRegionWidth() + 2, region.getRegionHeight() + 2,
                        pixmap.getFormat());
                int x;
                int y;

                //draw 9 patch lines
                savePixmap.setColor(Color.BLACK);

                if (region.splits != null) {
                    x = 0;
                    for (y = region.splits[2] + 1; y < savePixmap.getHeight() - region.splits[3] - 1; y++) {
                        savePixmap.drawPixel(x, y);
                    }

                    y = 0;
                    for (x = region.splits[0] + 1; x < savePixmap.getWidth() - region.splits[1] - 1; x++) {
                        savePixmap.drawPixel(x, y);
                    }
                }

                if (region.pads != null) {
                    x = savePixmap.getWidth() - 1;
                    for (y = region.pads[2] + 1; y < savePixmap.getHeight() - region.pads[3] - 1; y++) {
                        savePixmap.drawPixel(x, y);
                    }

                    y = savePixmap.getHeight() - 1;
                    for (x = region.pads[0] + 1; x < savePixmap.getWidth() - region.pads[1] - 1; x++) {
                        savePixmap.drawPixel(x, y);
                    }
                }

                for (x = 0; x < region.getRegionWidth(); x++) {
                    for (y = 0; y < region.getRegionHeight(); y++) {
                        int colorInt = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y);
                        savePixmap.drawPixel(x + 1, y + 1, colorInt);
                    }
                }
            }
            FileHandle outputFile = targetDirectory.child(name);
            PixmapIO.writePNG(outputFile, savePixmap);
            DrawableData drawable = new DrawableData(outputFile);

            //delete drawables with the same name
            for (DrawableData originalData : new Array<>(main.getProjectData().getAtlasData().getDrawables())) {
                if (originalData.name.equals(drawable.name)) {
                    main.getProjectData().getAtlasData().getDrawables().removeValue(originalData, true);
                }
            }

            drawables.add(drawable);
        }

    } else {
        throw new FileNotFoundException();
    }
}

From source file:com.uwsoft.editor.gdx.ui.AssetList.java

License:Apache License

public AssetList(final UIStage s, float width, float height) {
    this.setWidth(width);
    this.setHeight(height);
    final Table container = new Table();
    Table table = new Table();
    container.setX(0);/*from ww w  .  jav a 2s .  c  om*/
    container.setY(0);
    container.setWidth(getWidth() - 1);
    container.setHeight(getHeight() - 20);
    final ScrollPane scroll = new ScrollPane(table, s.textureManager.editorSkin);
    container.add(scroll).colspan(4).width(getWidth());
    container.row();
    scroll.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return true;
        }
    });
    scroll.setHeight(getHeight() - 20);
    scroll.setFlickScroll(false);
    TextureAtlas atlas = s.textureManager.getProjectAssetsList();

    HashMap<String, SpineAnimData> spineAnimations = s.textureManager.getProjectSpineAnimationsList();
    HashMap<String, TextureAtlas> spriteAnimations = s.textureManager.getProjectSpriteAnimationsList();
    HashMap<String, FileHandle> spriterAnimations = s.textureManager.getProjectSpriterAnimationsList();

    if (atlas == null)
        return;

    int itemIter = 0;
    for (int i = 0; i < atlas.getRegions().size; i++) {
        TextureAtlas.AtlasRegion atlasRegion = atlas.getRegions().get(i);
        boolean is9patch = atlasRegion.splits != null;
        final ImageThumbnailBox thumb = is9patch ? new Image9patchThumbnailBox(s, atlasRegion)
                : new ImageThumbnailBox(s, atlasRegion);

        table.add(thumb).pad(3);

        if ((itemIter - 7) % 4 == 0) {
            table.row();
        }
        itemIter++;
    }

    for (String animationName : spineAnimations.keySet()) {
        final SpineAnimationThumbnailBox thumb = new SpineAnimationThumbnailBox(s,
                spineAnimations.get(animationName));

        table.add(thumb).size(50, 50).pad(3);
        if ((itemIter - 7) % 4 == 0) {

            table.row();
        }
        itemIter++;
    }

    for (String animationName : spriteAnimations.keySet()) {
        final SpriteAnimationThumbnailBox thumb = new SpriteAnimationThumbnailBox(s, animationName);

        table.add(thumb).size(50, 50).pad(3);
        if ((itemIter - 7) % 4 == 0) {

            table.row();
        }
        itemIter++;
    }

    for (String animationName : spriterAnimations.keySet()) {
        final SpriterAnimationThumbnailBox thumb = new SpriterAnimationThumbnailBox(s, animationName);

        table.add(thumb).size(50, 50).pad(3);
        if ((itemIter - 7) % 4 == 0) {

            table.row();
        }
        itemIter++;
    }

    addActor(container);
}