[SOLVED] More problems with arrays to create tiles

I’ve figured out how to clone the geometry but I can not see subsequent geometries; can somone help me?

Box wall = new Box(1,1,1);
    geomWall = new Geometry("Box",wall);
    Material wallMat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
    wallMat.setColor("Color",ColorRGBA.Cyan);
    geomWall.setMaterial(mat);
    
    Box longWall = new Box(20,1,1);
    geomLongWall = new Geometry("Box",wall);
    Material matLongWall = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matLongWall.setColor("Color",ColorRGBA.Red);
    geomLongWall.setMaterial(matLongWall);
    
    Box tallWall = new Box(1,20,1);
    geomTallWall = new Geometry("Box",wall);
    Material matTallWall = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matTallWall.setColor("Color",ColorRGBA.Red);
    geomTallWall.setMaterial(matTallWall);
   
    int[][] map =
{
    {2},
    {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {3},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {2},
};
    
    map[0][0] = 2;
    map[13][13] = 2;
    
    for(int i = 0; i < map.length; i++){
        
        for (int j = 0; j < map[i].length; j++){
            
            switch (map[i][j]) {
                case 1:
                    geom = geomWall.clone(true);
                    geom.setLocalTranslation(i,j,1f);
                    geom.setLocalScale(1f,1f,1f);
                    break;
                case 2:
                    geomCloneLong = geomLongWall.clone(true);
                    geomCloneLong.setLocalTranslation(i,j,1f);
                    geomCloneLong.setLocalScale(20f,1f,1f);
                    break;
                case 3:
                    geomCloneTall = geomTallWall.clone(true);
                    geomCloneLong.setLocalTranslation(i,j,1f);
                    geomCloneLong.setLocalScale(1f,20f,1f);
                    break;
                default:
                    break;
            }
            
        }
        
    }

If you mean that you cannot see them, it dosen’t look like you’ve attached them to your rootNode.

I have but it still will not show up

And you’ve already read the Spatials page on the wiki?
https://wiki.jmonkeyengine.org/jme3/advanced/spatial.html#what-is-a-clone

Yes and it doesn’t help me since only one will show up but the others wont

Maybe it’s too big because the boxes are scaled to 800.
You should also know that the Box(f, f, f) constructor’s arguments are the extends, not the size, so the final box size will be twice the value.

oh, your Geometry doesn’t use the longWall/tallWall mesh

As far as the code you posted, you never called clone(); on your boxes

I thought they did since I defined them as boxes. I’m new to the JMonkey library

Edit: I see what you mean, I fixed it but now the small wall geoms won’t show up

======

Your loop doesn’t contain the code that attaches the cloned objects.

1 Like

He said he did already, and no cigar.

I did not know you had to attach the geoms to the rootnode inside the loop. Thanks for the help! I can finally see all of my geoms

3 Likes

Never ever believe it unless you see the code.

By definition, folks just learning how to program do not know what is/isn’t relevant in their code.

1 Like