0

我正在研究和引擎应用程序。在此,我在用户单击时插入精灵并使用小矩形绘制一个圆圈。我通过循环创建了许多矩形并将它们排列在圆形路径上,所以它看起来像一个圆形。但问题是屏幕响应缓慢并且看起来像挂起。任何人都可以建议我怎样才能让它更顺畅.. 这是我的代码。

//变量

private static final FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);


    private BitmapTextureAtlas mBitmapTextureAtlas;

    private TiledTextureRegion mBoxFaceTextureRegion;

    private Scene mScene;

    private PhysicsWorld mPhysicsWorld;

//场景方法

@Override
    public Scene onCreateScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());

        this.mScene = new Scene();
        this.mScene.setBackground(new Background(0, 0, 0));
        this.mScene.setOnSceneTouchListener(this);

        this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);

        final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
        final Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2, vertexBufferObjectManager);
        final Rectangle roof = new Rectangle(0, 0, CAMERA_WIDTH, 2, vertexBufferObjectManager);
        final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
        final Rectangle right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);

        final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);

        this.mScene.attachChild(ground);
        this.mScene.attachChild(roof);
        this.mScene.attachChild(left);
        this.mScene.attachChild(right);
        drawLine();
        this.mScene.registerUpdateHandler(this.mPhysicsWorld);

        return this.mScene;
    }

//在drawline方法中:

private void drawLine() {


        float x1,y1,x2=1,y2=1;
        float r=100;
        float xCenter=300,yCenter=300;
        Rectangle rectTest;

        for(double i=0;i<5;i+=.01){
                x1 = (float) (xCenter + r * Math.cos(i));  
                y1 = (float) (yCenter + r * Math.sin(i));

                System.out.println("RECT x1="+x1);
                System.out.println("RECT y1="+y1);
                System.out.println("RECT x2="+x2);
                System.out.println("RECT y3="+y2);

             rectTest = new Rectangle(x1,y1,1,1,getVertexBufferObjectManager());

            rectTest.setColor(Color.RED);
            FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
                    0.1f, 0.1f);
            PhysicsFactory.createBoxBody(this.mPhysicsWorld, rectTest,
                    BodyType.StaticBody, wallFixtureDef);
            this.mScene.attachChild(rectTest);

        }
}
4

1 回答 1

1

问题可能是您正在使用 Box2D 创建 500 个动态主体对象。Box2D 或任何物理引擎在移动平台上的成本相对较高。模拟 500 个碰撞体正在推动移动处理器处理的极限。尝试使用 50 个以下的对象来定义您的圈子。

于 2013-09-27T19:38:26.563 回答