Scene2d |在30个Actors上调用rotateBy会导致android上的fps低

时间:2016-09-14 17:52:28

标签: libgdx scene2d

我有一个游戏,我的物体不断围绕中心点旋转。问题是,当我同时在超过20个演员上调用rotateBy时,fps从60 fps下降到30.这是正常行为吗?旋转30个演员如何导致fps下降?

编辑:我还应该注意每个演员都有一个身体,并且每个帧都会销毁并重新创建灯具(因为演员会改变大小)。

编辑这里是代码,这称为每个actor的每个帧。

private void createFixtures(boolean remove) {

    if (remove) {
        if (fixture_inner != null) {
            if (body.getFixtureList().contains(fixture_inner, false)) {
                body.destroyFixture(fixture_inner);
            }
        }
        if (fixture_outer != null) {
            if (body.getFixtureList().contains(fixture_outer, false)) {
                body.destroyFixture(fixture_outer);
            }
        }
        if (fixture_gap != null) {
            if (body.getFixtureList().contains(fixture_gap, false)) {
                body.destroyFixture(fixture_gap);
            }
        }
        if (fixture_innerCircle != null) {
            if (body.getFixtureList().contains(fixture_innerCircle, false)) {
                body.destroyFixture(fixture_innerCircle);
            }
        }
        if (fixture_outerCircle != null) {
            if (body.getFixtureList().contains(fixture_outerCircle, false)) {
                body.destroyFixture(fixture_outerCircle);
            }
        }
    }

    if (getInnerBounds() != null) {
        FixtureDef fixtureDef_inner = new FixtureDef();
        PolygonShape shape_inner = new PolygonShape();
        shape_inner.set(getInnerBounds().getTransformedVertices());
        fixtureDef_inner.shape = shape_inner;
        fixtureDef_inner.filter.categoryBits = Config.CATEGORYBIT_BLOCKER;
        fixtureDef_inner.filter.maskBits = Config.CATEGORYBIT_PLAYER;
        fixtureDef_inner.isSensor = true;
        fixture_inner = body.createFixture(fixtureDef_inner);
        BlockerFixtureUserData fixtureUserData_inner = new BlockerFixtureUserData(this, gameObjects.indexOf(this, false));
        fixture_inner.setUserData(fixtureUserData_inner);
        shape_inner.dispose();

    }

    if (getInnerCircleBounds() != null) {
        FixtureDef fixtureDef_circle = new FixtureDef();
        PolygonShape shape_circle = new PolygonShape();
        shape_circle.set(getInnerCircleBounds().getTransformedVertices());
        fixtureDef_circle.shape = shape_circle;
        fixtureDef_circle.filter.categoryBits = Config.CATEGORYBIT_BLOCKER;
        fixtureDef_circle.filter.maskBits = Config.CATEGORYBIT_PLAYER;
        fixtureDef_circle.isSensor = true;
        fixture_innerCircle = body.createFixture(fixtureDef_circle);
        BlockerFixtureUserData fixtureUserData_circle = new BlockerFixtureUserData(this, gameObjects.indexOf(this, false));
        fixture_innerCircle.setUserData(fixtureUserData_circle);
        shape_circle.dispose();
    }

    if (getOuterCircleBounds() != null) {
        FixtureDef fixtureDef_circle = new FixtureDef();
        PolygonShape shape_circle = new PolygonShape();
        shape_circle.set(getOuterCircleBounds().getTransformedVertices());
        fixtureDef_circle.shape = shape_circle;
        fixtureDef_circle.filter.categoryBits = Config.CATEGORYBIT_BLOCKER;
        fixtureDef_circle.filter.maskBits = Config.CATEGORYBIT_PLAYER;
        fixtureDef_circle.isSensor = true;
        fixture_outerCircle = body.createFixture(fixtureDef_circle);
        BlockerFixtureUserData fixtureUserData_circle = new BlockerFixtureUserData(this, gameObjects.indexOf(this, false));
        fixture_outerCircle.setUserData(fixtureUserData_circle);
        shape_circle.dispose();
    }

    if (getOuterBounds() != null) {
        FixtureDef fixtureDef_outer = new FixtureDef();
        PolygonShape shape_outer = new PolygonShape();
        shape_outer.set(getOuterBounds().getTransformedVertices());
        fixtureDef_outer.shape = shape_outer;
        fixtureDef_outer.filter.categoryBits = Config.CATEGORYBIT_BLOCKER;
        fixtureDef_outer.filter.maskBits = Config.CATEGORYBIT_PLAYER;
        fixtureDef_outer.isSensor = true;
        fixture_outer = body.createFixture(fixtureDef_outer);
        BlockerFixtureUserData fixtureUserData_outer = new BlockerFixtureUserData(this, gameObjects.indexOf(this, false));
        fixture_outer.setUserData(fixtureUserData_outer);

        shape_outer.dispose();
    }

    if (getGapBounds() != null) {
        FixtureDef fixtureDef_gap = new FixtureDef();
        PolygonShape shape_gap = new PolygonShape();
        shape_gap.set(getGapBounds().getTransformedVertices());
        fixtureDef_gap.shape = shape_gap;
        fixtureDef_gap.filter.categoryBits = Config.CATEGORYBIT_BLOCKERGAP;
        fixtureDef_gap.filter.maskBits = Config.CATEGORYBIT_PLAYER;
        fixtureDef_gap.isSensor = true;
        fixture_gap = body.createFixture(fixtureDef_gap);
        BlockerFixtureUserData fixtureUserData_gap = new BlockerFixtureUserData(this, gameObjects.indexOf(this, false));
        fixture_gap.setUserData(fixtureUserData_gap);

        shape_gap.dispose();
    }
}

1 个答案:

答案 0 :(得分:0)

如果你在每一帧中销毁并重新创建灯具,那么你每秒钟会做1800次。您可以独立于帧速率(即每秒10次,相当于30个演员每秒300次),而不是破坏和重新创建每一帧。

这将显着减少游戏中必须进行的处理量,并且您可以在尺寸之间进行插值,以便向用户呈现流畅的动画。