List of usage examples for com.badlogic.gdx.utils Array clear
public void clear()
From source file:MyGdxGame.java
License:Apache License
private void getTiles(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) { TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("walls"); rectPool.freeAll(tiles);/* w w w .java2 s. com*/ tiles.clear(); for (int y = startY; y <= endY; y++) { for (int x = startX; x <= endX; x++) { Cell cell = layer.getCell(x, y); if (cell != null) { Rectangle rect = rectPool.obtain(); rect.set(x, y, 1, 1); tiles.add(rect); } } } }
From source file:ch.coldpixel.mario.Sprites.Mario.java
public Mario(World world, PlayScreen screen) { super(screen.getAtlas().findRegion("little_mario")); this.world = world; currentState = State.STANDING; previousState = State.STANDING; stateTimer = 0;/*from w w w . j av a 2 s. c om*/ runningRight = true; Array<TextureRegion> frames = new Array<TextureRegion>(); for (int i = 1; i < 4; i++) { frames.add(new TextureRegion(getTexture(), i * 16, 0, 16, 16)); } marioRun = new Animation(0.1f, frames); frames.clear(); for (int i = 4; i < 6; i++) { frames.add(new TextureRegion(getTexture(), i * 16, 0, 16, 16)); } marioJump = new Animation(0.1f, frames); marioStand = new TextureRegion(getTexture(), 0, 0, 16, 16); defineMario(); setBounds(0, 0, 16 / MarioBros.PPM, 16 / MarioBros.PPM); setRegion(marioStand); }
From source file:com.badlogic.gdx.tests.superkoalio.SuperKoalio.java
License:Apache License
private void getTiles(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) { TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1); rectPool.freeAll(tiles);//from w ww. j a va 2s. c o m tiles.clear(); for (int y = startY; y <= endY; y++) { for (int x = startX; x <= endX; x++) { Cell cell = layer.getCell(x, y); if (cell != null) { Rectangle rect = rectPool.obtain(); rect.set(x, y, 1, 1); tiles.add(rect); } } } }
From source file:com.badlydrawngames.general.Grid.java
License:Apache License
public void clear() { for (Array<Rectangle> v : grid) { v.clear(); } }
From source file:com.badlydrawngames.general.Pools.java
License:Apache License
/** Frees the items in an array to a pool. * @param <T> the type of item allocated in the array. * @param array the array of items to free. * @param pool the pool that the items are to be released to. */ public static <T> void freeArrayToPool(Array<T> array, Pool<T> pool) { pool.freeAll(array);/* w w w . j a v a 2s . com*/ array.clear(); }
From source file:com.bladecoder.engineeditor.ui.components.ScopePanel.java
License:Apache License
public void clear() { Array<TextButton> buttons = buttonGroup.getButtons(); buttons.clear(); hPanel.clear(); }
From source file:com.bladecoder.engineeditor.ui.components.TabPanel.java
License:Apache License
public void clear() { Array<Button> buttons = buttonGroup.getButtons(); buttons.clear(); header.clear();// w ww . j av a 2 s . c o m tabs.clear(); body.setActor(null); body.clear(); }
From source file:com.company.minery.utils.spine.SkeletonBounds.java
License:Open Source License
public void update(Skeleton skeleton, boolean updateAabb) { Array<BoundingBoxAttachment> boundingBoxes = this.boundingBoxes; Array<FloatArray> polygons = this.polygons; Array<Slot> slots = skeleton.slots; int slotCount = slots.size; boundingBoxes.clear(); polygonPool.freeAll(polygons);//w w w. j a v a2 s . c o m polygons.clear(); for (int i = 0; i < slotCount; i++) { Slot slot = slots.get(i); Attachment attachment = slot.attachment; if (attachment instanceof BoundingBoxAttachment) { BoundingBoxAttachment boundingBox = (BoundingBoxAttachment) attachment; boundingBoxes.add(boundingBox); FloatArray polygon = polygonPool.obtain(); polygons.add(polygon); int vertexCount = boundingBox.getVertices().length; polygon.ensureCapacity(vertexCount); polygon.size = vertexCount; boundingBox.computeWorldVertices(slot.bone, polygon.items); } } if (updateAabb) aabbCompute(); }
From source file:com.cyphercove.doublehelix.points.BillboardDecalBatch.java
License:Apache License
public void add(BillboardDecal decal) { int groupIndex = groupStrategy.decideBillboardGroup(decal); Array<BillboardDecal> targetGroup = groupList.get(groupIndex); if (targetGroup == null) { targetGroup = groupPool.obtain(); targetGroup.clear(); usedGroups.add(targetGroup);//w w w . j a v a 2s . com groupList.insert(groupIndex, targetGroup); } targetGroup.add(decal); }
From source file:com.esotericsoftware.spine.utils.Triangulator.java
License:Open Source License
public Array<FloatArray> decompose(FloatArray verticesArray, ShortArray triangles) { float[] vertices = verticesArray.items; Array<FloatArray> convexPolygons = this.convexPolygons; polygonPool.freeAll(convexPolygons); convexPolygons.clear(); Array<ShortArray> convexPolygonsIndices = this.convexPolygonsIndices; polygonIndicesPool.freeAll(convexPolygonsIndices); convexPolygonsIndices.clear();// w w w . j a va2 s .c om ShortArray polygonIndices = polygonIndicesPool.obtain(); polygonIndices.clear(); FloatArray polygon = polygonPool.obtain(); polygon.clear(); // Merge subsequent triangles if they form a triangle fan. int fanBaseIndex = -1, lastWinding = 0; short[] trianglesItems = triangles.items; for (int i = 0, n = triangles.size; i < n; i += 3) { int t1 = trianglesItems[i] << 1, t2 = trianglesItems[i + 1] << 1, t3 = trianglesItems[i + 2] << 1; float x1 = vertices[t1], y1 = vertices[t1 + 1]; float x2 = vertices[t2], y2 = vertices[t2 + 1]; float x3 = vertices[t3], y3 = vertices[t3 + 1]; // If the base of the last triangle is the same as this triangle, check if they form a convex polygon (triangle fan). boolean merged = false; if (fanBaseIndex == t1) { int o = polygon.size - 4; float[] p = polygon.items; int winding1 = winding(p[o], p[o + 1], p[o + 2], p[o + 3], x3, y3); int winding2 = winding(x3, y3, p[0], p[1], p[2], p[3]); if (winding1 == lastWinding && winding2 == lastWinding) { polygon.add(x3); polygon.add(y3); polygonIndices.add(t3); merged = true; } } // Otherwise make this triangle the new base. if (!merged) { if (polygon.size > 0) { convexPolygons.add(polygon); convexPolygonsIndices.add(polygonIndices); } else { polygonPool.free(polygon); polygonIndicesPool.free(polygonIndices); } polygon = polygonPool.obtain(); polygon.clear(); polygon.add(x1); polygon.add(y1); polygon.add(x2); polygon.add(y2); polygon.add(x3); polygon.add(y3); polygonIndices = polygonIndicesPool.obtain(); polygonIndices.clear(); polygonIndices.add(t1); polygonIndices.add(t2); polygonIndices.add(t3); lastWinding = winding(x1, y1, x2, y2, x3, y3); fanBaseIndex = t1; } } if (polygon.size > 0) { convexPolygons.add(polygon); convexPolygonsIndices.add(polygonIndices); } // Go through the list of polygons and try to merge the remaining triangles with the found triangle fans. for (int i = 0, n = convexPolygons.size; i < n; i++) { polygonIndices = convexPolygonsIndices.get(i); if (polygonIndices.size == 0) continue; int firstIndex = polygonIndices.get(0); int lastIndex = polygonIndices.get(polygonIndices.size - 1); polygon = convexPolygons.get(i); int o = polygon.size - 4; float[] p = polygon.items; float prevPrevX = p[o], prevPrevY = p[o + 1]; float prevX = p[o + 2], prevY = p[o + 3]; float firstX = p[0], firstY = p[1]; float secondX = p[2], secondY = p[3]; int winding = winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); for (int ii = 0; ii < n; ii++) { if (ii == i) continue; ShortArray otherIndices = convexPolygonsIndices.get(ii); if (otherIndices.size != 3) continue; int otherFirstIndex = otherIndices.get(0); int otherSecondIndex = otherIndices.get(1); int otherLastIndex = otherIndices.get(2); FloatArray otherPoly = convexPolygons.get(ii); float x3 = otherPoly.get(otherPoly.size - 2), y3 = otherPoly.get(otherPoly.size - 1); if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; int winding1 = winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); int winding2 = winding(x3, y3, firstX, firstY, secondX, secondY); if (winding1 == winding && winding2 == winding) { otherPoly.clear(); otherIndices.clear(); polygon.add(x3); polygon.add(y3); polygonIndices.add(otherLastIndex); prevPrevX = prevX; prevPrevY = prevY; prevX = x3; prevY = y3; ii = 0; } } } // Remove empty polygons that resulted from the merge step above. for (int i = convexPolygons.size - 1; i >= 0; i--) { polygon = convexPolygons.get(i); if (polygon.size == 0) { convexPolygons.removeIndex(i); polygonPool.free(polygon); polygonIndices = convexPolygonsIndices.removeIndex(i); polygonIndicesPool.free(polygonIndices); } } return convexPolygons; }