Having problems with a game mechanic I can't remember the name of ^^

Basically I want to make a 2D space shooter with 3D graphics and therefore I need a starfield.
I got to the point where I could make a finite starfield with a ParticleEmitter which obviously makes the game slower the bigger it is generated.

I then got the idea of this mechanic I can’t remember the name of so I describe it:

Basically I can already make 9 starfields which have the size of the computer screen so you can think of it like this with the “o” being the visible starfield.

xxa
xox
xxx

Now if I get closer to the “a” for example I want the other “x” to first kill all the particles then move to the empty “slots” around “a” and respawn their particles in the new location so it would look like this with now the “a” being the visible starfield.

xxx
xax
oxx

I already got pretty close to the wanted result but the “x” or whatever you want to call the non-visible emitters don’t go into the empty slots :frowning:
So now it kind of looks like this with “s” being spazzing out starfields ^^

s
ax

I don’t include my code right away because it is really a lot and also very confusing … I think there has to be an easy way of doing this so please help me if you have some ideas for this.
I would also be happy if someone could tell me the name of this mechanic so I can search the interwebs :smiley:

Paging?

@nehon said: Paging?

Thanks I looked it up and now I use @anthyon and @Sploreg Terrain Grid.
But it still doesn’t really work and I don’t know why.
This time I can post some code:

[java]
private TerrainGrid grid;

@Override
public void simpleInitApp() {
    Material matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Pink);
    int size = 129;          //FastMath.nearestPowerOfTwo((int)GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds().getWidth())+1;
    this.grid = new TerrainGrid("terrain", size, size, new ImageTileLoader(assetManager, new Namer() {
        public String getName(int x, int y) {
            return "Scenes/TerrainMountains/terrain_" + x + "_" + y + ".png";
        }
    }));
    
    this.grid.addListener(this);
    this.grid.setMaterial(matWire);
    this.grid.setLocalTranslation(0, 0, 0);
    int scaleWidth = 1;
    this.grid.setLocalScale(scaleWidth, scaleWidth, scaleWidth);
    this.rootNode.attachChild(this.grid);

    TerrainLodControl control = new TerrainGridLodControl(this.grid, starshoot.getCamera());
    control.setLodCalculator(new DistanceLodCalculator(3, 2.7f));          // patch size, and a multiplier
    this.grid.addControl(control);
}

public ParticleEmitter createField(float x, float y, float z, float width) {
    Material starMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    starMat.setBoolean("PointSprite", true);
    starMat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
    Vector3f worldVec = grid.toWorldSpace(new Vector3f(x, -y, z));
    float depth = 1000 + worldVec.getY();
    long density = 900000;
    float fieldWidth = width * 2;
    int fieldAmount = (int) ((depth * fieldWidth * fieldWidth) / density);
    ParticleEmitter emit = new ParticleEmitter("StarfieldEmitter_" + x + "_" + z, ParticleMesh.Type.Point, fieldAmount);
    emit.setLocalTranslation(worldVec);
    emit.setShape(new EmitterBoxShape(new Vector3f(-fieldWidth / 2, 0, -fieldWidth / 2), new Vector3f(fieldWidth / 2, -depth, fieldWidth / 2)));
    emit.setGravity(0, 0, 0);
    emit.setLowLife(Integer.MAX_VALUE);
    emit.setHighLife(Integer.MAX_VALUE);
    emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
    emit.setImagesX(15);
    emit.setStartSize(0.3f);
    emit.setEndSize(0.3f);
    emit.setStartColor(ColorRGBA.White);
    emit.setEndColor(ColorRGBA.White);
    emit.setSelectRandomImage(true);
    emit.setParticlesPerSec(0);
    emit.setMaterial(starMat);
    return emit;
}

public void tileAttached(Vector3f cell, TerrainQuad quad) {
    ParticleEmitter emitter = this.createField(cell.getX(), grid.toCellSpace(new Vector3f(0, 100, 0)).getY(), cell.getZ(), quad.getTerrainSize());
    rootNode.attachChild(emitter);
    emitter.emitAllParticles();
}

public void tileDetached(Vector3f cell, TerrainQuad quad) {
    cell = grid.toCellSpace(grid.toWorldSpace(cell));
    ParticleEmitter emitter = (ParticleEmitter) rootNode.getChild("StarfieldEmitter_" + cell.getX() + "_" + cell.getZ());
    if (emitter != null) {
        emitter.killAllParticles();
        rootNode.detachChild(emitter);
    }
}[/java]  

The old emitters don’t always get deleted and the new emitters get created too late.