Android Studio创建示例游戏时出错

时间:2016-02-07 04:38:13

标签: android android-studio libgdx

package com.mygame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.Shape;
import com.badlogic.gdx.physics.box2d.World;
import com.mygame.desktop.BaseScreen;

/**
 * Created by Felipe on 2/5/2016.
 */
public class Box2DScreen extends BaseScreen {
    public Box2DScreen(MainGame game) {
        super(game);
    }

    private World world;

    private Box2DDebugRenderer renderer;

    private OrthographicCamera camera;

    private Body blockmanBody, floorBody, stingBody;

    private Fixture blockmanFixture, floorFixture, stingFixture;


    @Override
    public void show() {
        world = new World(new Vector2(0, -10),true);
        renderer = new Box2DDebugRenderer();
        camera = new OrthographicCamera(7.11f, 4);
        camera.translate(2, 1);

        blockmanBody = world.createBody(createblockmanBodyDef());
        floorBody = world.createBody(createfloorBodyDef());
        stingBody = world.createBody(createStingBodyDef(1));


        PolygonShape blockmanShape = new PolygonShape();
        blockmanShape.setAsBox(0.5f, 0.5f);
        blockmanFixture = blockmanBody.createFixture(blockmanShape, 1);
        blockmanShape.dispose();

        PolygonShape floorShape = new PolygonShape();
        floorShape.setAsBox(500, 1);
        floorFixture = floorBody.createFixture(floorShape, 1);
        floorShape.dispose();

        stingBody = createStingFixture(stingBody);
    }


    private BodyDef createStingBodyDef(float x) {
        BodyDef def = new BodyDef();
        def.position.set(x, 0.5f);
        return def;
    }

    private BodyDef createfloorBodyDef() {
        BodyDef def = new BodyDef();
        def.position.set(0, -1);
        return def;
    }

    private BodyDef createblockmanBodyDef() {
        BodyDef def = new BodyDef();
        def.position.set(0, 10);
        def.type = BodyDef.BodyType.DynamicBody;
        return def;
    }

    private Fixture createStingFixture(Body stingBody) {
        Vector2[] vertices = new Vector2[3];
        vertices[0] = new Vector2(-0.5f, -0.5f);
        vertices[1] = new Vector2(0.5f, -0.5f);
        vertices[2] = new Vector2(0, 0.5f);

       PolygonShape shape = new PolygonShape();
        shape.set(vertices);
        Fixture fix = stingBody.createFixture(shape, 1);
        shape.dispose();
        return fix;
    }

    @Override
    public void dispose() {
        floorBody.destroyFixture(floorFixture);
        blockmanBody.destroyFixture(blockmanFixture);
        stingBody.destroyFixture(stingFixture);
        world.destroyBody(blockmanBody);
        world.destroyBody(floorBody);
        world.destroyBody(stingBody);
        world.dispose();
        renderer.dispose();
    }

    @Override
    public void render(float delta) {
       Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        world.step(delta, 6, 2);
        camera.update();
        renderer.render(world, camera.combined);
    }
}

我正在关注https://www.youtube.com/watch?v=5S3AEYYo45s&index=26&list=PLraIUviMMM3duiko5MtkFPN2vhm0URmkE

的教程

我该如何解决这个问题?请帮助我!程序开始抱怨以下错误('错误:(56,38)Gradle:错误:不兼容的类型:Fixture无法转换为Body')。

1 个答案:

答案 0 :(得分:1)

这是因为代码

com.microsoft.bingads.InternalException: Internal BingAds SDK exception has occured
at com.microsoft.bingads.internal.LiveComOAuthService.getAccessTokens(LiveComOAuthService.java:101) ~[microsoft.bingads-10.4.2.jar:na]
at com.microsoft.bingads.internal.OAuthWithAuthorizationCode.requestAccessAndRefreshTokens(OAuthWithAuthorizationCode.java:110) ~[microsoft.bingads-10.4.2.jar:na]
at com.microsoft.bingads.internal.OAuthWithAuthorizationCode.refreshTokensIfNeeded(OAuthWithAuthorizationCode.java:142) ~[microsoft.bingads-10.4.2.jar:na]

我认为你打算写

stingBody = createStingFixture(stingBody);