Libgdx NESTED ShapeRenderer not drawing lines

柔情痞子 提交于 2019-12-13 05:48:47

问题


In the code below I retrieve an arraylist of vertices (I've debugged and they are in fact there) and then attempt to render them in this nest loop arrangement which is hosted in the render method. For some reason, the ShapeRenderer cannot connect all the lines if this is nested? Can someone tell me what I'm doing wrong? Nothing is being drawn to the screen; I get no errors.

    shapeRenderer.setProjectionMatrix(camera.combined);
    shapeRenderer.begin(ShapeType.Line);
    for(int i = 0;i<tmpBodies.size;i++)
    {   
        if(tmpBodies.get(i).getType().equals(BodyType.DynamicBody) && 
           !tmpBodies.get(i).equals(car.getChassis()) &&
           !tmpBodies.get(i).equals(car.rightWheel)&& 
           !tmpBodies.get(i).equals(car.leftWheel)&& 
           !tmpBodies.get(i).equals(terrain))  // tmpBodies.get(i).getFixtureList().get(0).getShape().equals(Type.Chain)
        {
            ChainShape tempShape = new ChainShape();
            ArrayList<Vector2> bodyPoints = new ArrayList<Vector2>();

            tempShape = (ChainShape)tmpBodies.get(i).getFixtureList()
                                    .get(0).getShape();

            for(int q=0; q<tempShape.getVertexCount(); q++)
            {
                Vector2 linePoints = new Vector2();

                tempShape.getVertex(q, linePoints);

                Vector2 newLinePoints = tmpBodies.get(i).getWorldPoint(linePoints);
                bodyPoints.add(newLinePoints);
            }

            for(int z=0; z<tempShape.getVertexCount()-1; z++)
            {
                shapeRenderer.setColor(1, 1, 0, 1);
                shapeRenderer.line(bodyPoints.get(z).x,
                                   bodyPoints.get(z).y,
                                   bodyPoints.get(z+1).x,
                                   bodyPoints.get(z+1).y);
            }
        }
    }

回答1:


not if I explain well, that is, possible? you need use another matrix4, if using box2d eg units for PPM.

shapeRenderer.setProjectionMatrix(camera.combined);

change for example:

testMatrix4 Matrix4; //<-- Variable Class. 

//in Your code

//Other Code

//batch or Camera Matrix

testMatrix4 = batch.getProyectionMatrix().cpy()
                .scale(YOUR_PPM_X, YOUR_PPM_Y, 0);

shapeRenderer.setProjectionMatrix(testMatrix4);

//Other Code

I never did something like this, but if it does not work, notify me, that I erase.



来源:https://stackoverflow.com/questions/28798600/libgdx-nested-shaperenderer-not-drawing-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!