Libgdx嵌套ShapeRenderer不画线 [英] Libgdx NESTED ShapeRenderer not drawing lines

查看:267
本文介绍了Libgdx嵌套ShapeRenderer不画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code下面我找回顶点的ArrayList(我已经调试,他们其实有),然后尝试使他们这是在渲染方法托管于该窝循环安排。出于某种原因,如果这是嵌套在ShapeRenderer无法连接的所有行?谁能告诉我,我做错了什么?没有什么是被绘制到屏幕上;我没有得到任何错误。

  shapeRenderer.setProjectionMatrix(camera.combined);
    shapeRenderer.begin(ShapeType.Line);
    的for(int i = 0; I< tmpBodies.size;我++)
    {
        。如果(tmpBodies.get(ⅰ).getType()等于(BodyType.DynamicBody)及&放大器;
           !tmpBodies.get(ⅰ).equals(car.getChassis())及&放大器;
           !tmpBodies.get(ⅰ).equals(car.rightWheel)及&放大器;
           !tmpBodies.get(ⅰ).equals(car.leftWheel)及&放大器;
           !tmpBodies.get(I).equals(地形))// tmpBodies.get(I).getFixtureList()得到(0).getShape()。等于(Type.Chain)
        {
            ChainShape tempShape =新ChainShape();
            ArrayList的< Vector2> bodyPoints =新的ArrayList< Vector2>();            tempShape =(ChainShape)tmpBodies.get(I).getFixtureList()
                                    获得(0).getShape();            对于(INT Q = 0; Q< tempShape.getVertexCount();问++)
            {
                Vector2 linePoints =新Vector2();                tempShape.getVertex(Q,linePoints);                Vector2 newLinePoints = tmpBodies.get(I).getWorldPoint(linePoints);
                bodyPoints.add(newLinePoints);
            }            对于(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);
            }
        }
    }


解决方案

不是,如果我解释好,也就是说,可能吗?你需要使用另一个matrix4,如果使用的Box2D比如单位PPM。

shapeRenderer.setProjectionMatrix(camera.combined);

例如变化:

  testMatrix4 Matrix4; //<  - 可变类。

//在你的code

  //其他code//批处理或摄像头矩阵testMatrix4 = batch.getProyectionMatrix()。CPY()
                .scale(YOUR_PPM_X,YOUR_PPM_Y,0);shapeRenderer.setProjectionMatrix(testMatrix4);//其他code

我从来没有这样的事情,但如果它不能正常工作,请通知我,我抹去。

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);
            }
        }
    }

解决方案

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.

这篇关于Libgdx嵌套ShapeRenderer不画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆