private StarsSector getSector(int x, int y) { for (StarsSector tmp : this.starSectors) { if (tmp.getPos().x == x && tmp.getPos().y == y) { return tmp; } } return null; }
private StarsSector getOutsideSector(int x, int y) { for (StarsSector tmp : this.starSectors) { float distX = Maths.dist(tmp.getPos().x, x); float distY = Maths.dist(tmp.getPos().y, y); if (distX > 1 || distY > 1) { return tmp; } } return null; }
@Override protected void onManagedUpdate(float pSecondsElapsed) { int sectorX = (int) Math.floor(this.getSectorX(this.camera.getXMin() + this.camera.getWidth() / 2)); int sectorY = (int) Math.floor(this.getSectorY(this.camera.getYMin() + this.camera.getHeight() / 2)); if (sectorX != this.lastChangedSectorX || sectorY != this.lastChangedSectorY) for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { StarsSector tmp = this.getSector(sectorX + i, sectorY + j); if (tmp == null) { StarsSector tmp2 = this.getOutsideSector(sectorX, sectorY); if (tmp2 != null) { tmp2.setPosX(sectorX + i); tmp2.setPosY(sectorY + j); } } } } this.lastChangedSectorX = sectorX; this.lastChangedSectorY = sectorY; for (StarsSector sector : this.starSectors) { sector.getEntity().setX(sector.getPos().x * sectorW + this.camera.getXMin() * scrollFactor); sector.getEntity().setY(sector.getPos().y * sectorH + this.camera.getYMin() * scrollFactor); } this.camera.onUpdate(pSecondsElapsed); }
public StarsLayer( ZoomCamera camera, float scrollFactor, int count, Color blue, int width, int height, VertexBufferObjectManager manager, ArrayList<TextureRegion> starRegions) { this.camera = camera; this.scrollFactor = scrollFactor; this.sectorW = width; this.sectorH = height; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { StarsSector declareSector = declareSector(camera, count, blue, i, j, width, height, manager, starRegions); starSectors.add(declareSector); this.attachChild(declareSector.getEntity()); } } }