[LIBGDX学习]LibGDX代码详解(五)Box2D

import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.mygdx.game.box2d.ApplyForce;
import com.mygdx.game.box2d.BodyTypes;
import com.mygdx.game.box2d.Box2DTest;
import com.mygdx.game.box2d.Bridge;
import com.mygdx.game.box2d.Cantilever;
import com.mygdx.game.box2d.Chain;
import com.mygdx.game.box2d.CharacterCollision;
import com.mygdx.game.box2d.CollisionFiltering;
import com.mygdx.game.box2d.ContactListenerTest;
import com.mygdx.game.box2d.ContinuousTest;
import com.mygdx.game.box2d.ConveyorBelt;
import com.mygdx.game.box2d.DebugRendererTest;
import com.mygdx.game.box2d.OneSidedPlatform;
import com.mygdx.game.box2d.Prismatic;
import com.mygdx.game.box2d.Pyramid;
import com.mygdx.game.box2d.SimpleTest;
import com.mygdx.game.box2d.SphereStack;
import com.mygdx.game.box2d.VaryingRestitution;
import com.mygdx.game.box2d.VerticalStack;
import com.mygdx.game.utils.GdxTest;

import static com.badlogic.gdx.physics.box2d.Shape.Type.Chain;

public class Box2DTestCollection extends GdxTest implements InputProcessor, GestureListener {
    private final Box2DTest[] tests = {new DebugRendererTest(), new CollisionFiltering(), new Chain(), new Bridge(),
            new SphereStack(), new Cantilever(), new ApplyForce(), new ContinuousTest(), new Prismatic(), new CharacterCollision(),
            new BodyTypes(), new SimpleTest(), new Pyramid(), new OneSidedPlatform(), new VerticalStack(), new VaryingRestitution(),
            new ConveyorBelt()};

    private int testIndex = 0;

    private Application app = null;

    @Override
    public void render () {
        tests[testIndex].render();
    }

    @Override
    public void create () {
        if (this.app == null) {
            this.app = Gdx.app;
            Box2DTest test = tests[testIndex];
            test.create();
        }

        InputMultiplexer multiplexer = new InputMultiplexer();// 用来处理多个InputProcessor的情况
        multiplexer.addProcessor(this);
        multiplexer.addProcessor(new GestureDetector(this));// 第二个是gesture detector?
        Gdx.input.setInputProcessor(multiplexer);
    }

    @Override
    public void dispose () {
        tests[testIndex].dispose();
    }

    @Override
    public boolean keyDown (int keycode) {
        tests[testIndex].keyDown(keycode);

        return false;
    }

    @Override
    public boolean keyTyped (char character) {
        tests[testIndex].keyTyped(character);
        return false;
    }

    @Override
    public boolean keyUp (int keycode) {
        tests[testIndex].keyUp(keycode);
        return false;
    }

    @Override
    public boolean touchDown (int x, int y, int pointer, int button) {
        tests[testIndex].touchDown(x, y, pointer, button);
        return false;
    }

    @Override
    public boolean touchDragged (int x, int y, int pointer) {
        tests[testIndex].touchDragged(x, y, pointer);
        return false;
    }

    @Override
    public boolean touchUp (int x, int y, int pointer, int button) {
        tests[testIndex].touchUp(x, y, pointer, button);
        return false;
    }

    @Override
    public boolean mouseMoved (int x, int y) {
        return false;
    }

    @Override
    public boolean scrolled (int amount) {
        return false;
    }

    @Override
    public boolean touchDown (float x, float y, int pointer, int button) {
        return false;
    }

    @Override
    public boolean tap (float x, float y, int count, int button) {
        app.log("TestCollection", "disposing test '" + tests[testIndex].getClass().getName());
        tests[testIndex].dispose();
        testIndex++;
        if (testIndex >= tests.length) testIndex = 0;
        Box2DTest test = tests[testIndex];
        test.create();
        app.log("TestCollection", "created test '" + tests[testIndex].getClass().getName());
        return false;
    }

    @Override
    public boolean longPress (float x, float y) {
        return false;
    }

    @Override
    public boolean fling (float velocityX, float velocityY, int button) {
        return false;
    }

    @Override
    public boolean pan (float x, float y, float deltaX, float deltaY) {
        return false;
    }

    @Override
    public boolean panStop (float x, float y, int pointer, int button) {
        return false;
    }

    @Override
    public boolean zoom (float originalDistance, float currentDistance) {
        return false;
    }

    @Override
    public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) {
        return false;
    }

    @Override
    public void pinchStop () {
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值