Java Code Examples for com.badlogic.gdx.utils.Array#reverse()

The following examples show how to use com.badlogic.gdx.utils.Array#reverse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TeleportVisualizer.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private Array<TextureAtlas.AtlasRegion> compose(String name) {
    Array<TextureAtlas.AtlasRegion> result = composes.get(name);
    if (result == null) {
        result = new Array<TextureAtlas.AtlasRegion>(Config.findRegions(name));
        Array<TextureAtlas.AtlasRegion> rev = new Array<TextureAtlas.AtlasRegion>(result);
        rev.pop();
        rev.reverse();
        for (int i = 0; i < 1; i++) {
            result.add(result.get(result.size - 2));
            result.add(result.get(result.size - 2));
        }
        result.addAll(rev);
        composes.put(name, result);
    }
    return result;
}
 
Example 2
Source File: GridPacker.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
public Array<Page> pack (Array<Rect> inputRects) {
	if (!settings.silent) System.out.print("Packing");

	int cellWidth = 0, cellHeight = 0;
	for (int i = 0, nn = inputRects.size; i < nn; i++) {
		Rect rect = inputRects.get(i);
		cellWidth = Math.max(cellWidth, rect.width);
		cellHeight = Math.max(cellHeight, rect.height);
	}
	cellWidth += settings.paddingX;
	cellHeight += settings.paddingY;

	inputRects.reverse();

	Array<Page> pages = new Array();
	while (inputRects.size > 0) {
		Page result = packPage(inputRects, cellWidth, cellHeight);
		pages.add(result);
	}
	return pages;
}
 
Example 3
Source File: FileUtils.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
/**
 * Sorts file list, using this rules: directories first, sorted using provided comparator, then files sorted using provided comparator.
 * @param files list to sort
 * @param comparator comparator used to sort files list
 * @param descending if true then sorted list will be in reversed order
 * @return sorted file list
 */
public static Array<FileHandle> sortFiles (FileHandle[] files, Comparator<FileHandle> comparator, boolean descending) {
	Array<FileHandle> directoriesList = new Array<FileHandle>();
	Array<FileHandle> filesList = new Array<FileHandle>();

	for (FileHandle f : files) {
		if (f.isDirectory()) {
			directoriesList.add(f);
		} else {
			filesList.add(f);
		}
	}

	Sort sorter = new Sort();
	sorter.sort(directoriesList, comparator);
	sorter.sort(filesList, comparator);

	if (descending) {
		directoriesList.reverse();
		filesList.reverse();
	}

	directoriesList.addAll(filesList); // combine lists
	return directoriesList;
}
 
Example 4
Source File: SortingFilteringProvider.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
public SortingFilteringProvider setFilters(Array<Filter> filters) {
    if (filters == null) return this;
    this.filters.clear();
    this.filters.addAll(filters);
    filters.reverse();
    return this;
}
 
Example 5
Source File: AnimationDrawable.java    From TerraLegion with MIT License 5 votes vote down vote up
private static void addMiddleReversed(Array<TextureRegion> frames, boolean keepFirst) {
    if (frames.size < 3) {
        return;
    }
    Array<TextureRegion> middleReversed = new Array<TextureRegion>(frames);
    if (!keepFirst) {
        middleReversed.removeIndex(0);
    }
    middleReversed.removeIndex(middleReversed.size - 1);
    middleReversed.reverse();
    frames.addAll(middleReversed);
}
 
Example 6
Source File: Box2DMapObjectParser.java    From Entitas-Java with MIT License 5 votes vote down vote up
/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 */
public Fixture[] createFixtures(MapObject mapObject) {
    Polygon polygon;

    if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[]{createFixture(mapObject)};

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = toPolygonArray(toVector2Array(new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
    } else {
        Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
        convexPolygons = new Polygon[convexPolys.size];
        for (int i = 0; i < convexPolygons.length; i++)
            convexPolygons[i] = new Polygon(toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
    }

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject);
    }

    return fixtures;
}
 
Example 7
Source File: Box2DMapObjectParser.java    From Entitas-Java with MIT License 5 votes vote down vote up
/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 */
public Fixture[] createFixtures(MapObject mapObject) {
    Polygon polygon;

    if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[]{createFixture(mapObject)};

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = toPolygonArray(toVector2Array(new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
    } else {
        Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
        convexPolygons = new Polygon[convexPolys.size];
        for (int i = 0; i < convexPolygons.length; i++)
            convexPolygons[i] = new Polygon(toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
    }

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject);
    }

    return fixtures;
}