Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 发动机运动不平稳_Java_Android_Andengine - Fatal编程技术网

Java 发动机运动不平稳

Java 发动机运动不平稳,java,android,andengine,Java,Android,Andengine,我在测试发动机。我的代码为两个模拟重力和重力*2加速度的正方形设置动画,一个手动,另一个使用2DBox。 但我看到了运动的残缺。这正常吗?我怎样才能修好它 public class MainActivity extends BaseGameActivity { public static int WIDTH = 480; public static int HEIGHT = 800; public Scene mScene; public PhysicsWor

我在测试发动机。我的代码为两个模拟重力和重力*2加速度的正方形设置动画,一个手动,另一个使用2DBox。 但我看到了运动的残缺。这正常吗?我怎样才能修好它

public class MainActivity extends BaseGameActivity {

    public static int WIDTH = 480;
    public static int HEIGHT = 800;

    public Scene mScene;
    public PhysicsWorld mPhysicsWorld;
    public Body roofWallBody;

    private Body body;
    private final FixtureDef boxFixtureDef = PhysicsFactory.createFixtureDef(1f, 0f, 1f);

    @Override
    public Engine onCreateEngine(final EngineOptions pEngineOptions) {
        return new FixedStepEngine(pEngineOptions, 60);
    }

    @Override
    public EngineOptions onCreateEngineOptions() {
        EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED,
                new FillResolutionPolicy(), new Camera(0, 0, WIDTH, HEIGHT));
        engineOptions.getRenderOptions().setDithering(true);
        engineOptions.getRenderOptions().setMultiSampling(true);
        engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
        return engineOptions;
    }

    @Override
    public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) {

        pOnCreateResourcesCallback.onCreateResourcesFinished();
    }

    @Override
    public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) {
        mScene = new Scene();
        mScene.setBackground(new Background(0.9f, 0, 0.9f));
        pOnCreateSceneCallback.onCreateSceneFinished(mScene);
    }

    @Override
    public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) {

        mPhysicsWorld = new FixedStepPhysicsWorld(60, new Vector2(0f, SensorManager.GRAVITY_EARTH * 2), false, 3, 2);
        mScene.registerUpdateHandler(mPhysicsWorld);

        final FixtureDef WALL_FIXTURE_DEF = PhysicsFactory.createFixtureDef(0, 1f, 0.5f);
        final Rectangle floor = new Rectangle(0, HEIGHT - 3f, WIDTH, 3f, this.getVertexBufferObjectManager());
        roofWallBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, floor, BodyType.StaticBody, WALL_FIXTURE_DEF);
        this.mScene.attachChild(floor);

        IAreaShape box = new Rectangle(300f, 240f, 100, 100, mEngine.getVertexBufferObjectManager());
        body = PhysicsFactory.createBoxBody(mPhysicsWorld, box, BodyType.DynamicBody, boxFixtureDef);
        this.mScene.attachChild(box);
        mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(box, body));

        final Rectangle otherBox = new Rectangle(100, 100, 100, 100, getVertexBufferObjectManager()) {
            float velocity = 0;

            @Override
            protected void onManagedUpdate(float pSecondsElapsed) {
                super.onManagedUpdate(pSecondsElapsed);
                velocity += pSecondsElapsed * SensorManager.GRAVITY_EARTH;
                setPosition(getX(), getY() + velocity);
                if (getY() > HEIGHT) {
                    setPosition(getX(), 0);
                    velocity = 0;
                }
            }

        };
        otherBox.setColor(Color.YELLOW);
        this.mScene.attachChild(otherBox);

        pOnPopulateSceneCallback.onPopulateSceneFinished();
    }

}

您是在模拟器中测试,还是在设备上测试?您将无法在模拟器上获得合适的帧速率。(或者至少我从来没有这样做过)但任何设备都应该做到这一点。